1150 1

[Weka及其他] MATLAB课程:代码示例之Programming(五) [推广有奖]

企业贵宾

已卖:160份资源

巨擘

0%

还不是VIP/贵宾

-

威望
4
论坛币
624047 个
通用积分
180.5582
学术水平
918 点
热心指数
987 点
信用等级
841 点
经验
399203 点
帖子
9786
精华
48
在线时间
17322 小时
注册时间
2014-8-19
最后登录
2022-11-2

楼主
widen我的世界 学生认证  发表于 2016-3-9 14:52:55 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

MATLAB课程:代码示例之Programming(五)


Function Functions


This example shows how to use the output of one MATLAB® function as an input to another. This ability to specify a function's output as an input of another function serves a wide variety of purposes. Here we illustrate its use for finding zeros, optimization, and integration.


The HUMPS Function

A MATLAB function is a file that starts with the keyword function. This is what the function HUMPS looks like:

type humps


function [out1,out2] = humps(x)%HUMPS  A function used by QUADDEMO, ZERODEMO and FPLOTDEMO.%   Y = HUMPS(X) is a function with strong maxima near x = .3%   and x = .9.%%   [X,Y] = HUMPS(X) also returns X.  With no input arguments,%   HUMPS uses X = 0:.05:1.%%   Example:%      plot(humps)%%   See QUADDEMO, ZERODEMO and FPLOTDEMO.%   Copyright 1984-2014 The MathWorks, Inc.if nargin==0   x = 0:.05:1;endy = 1 ./ ((x-.3).^2 + .01) + 1 ./ ((x-.9).^2 + .04) - 6;if nargout==2,   out1 = x;   out2 = y;else   out1 = y;end


Plot of HUMPS

This figure shows a plot of HUMPS in the domain [0,2] using FPLOT.

fplot(@humps,[0,2]);


Zero of HUMPS

The FZERO function finds a zero of a function near an initial estimate. Our initial guess for the zero of HUMPS is 1.

z = fzero(@humps,1,optimset('Display','off'));fplot(@humps,[0,2]);hold on;plot(z,0,'r*');hold off


Minimum of HUMPS

The FMINBND function finds the minimum of a function in a given domain. Here, we search for a minimum for HUMPS in the domain (0.25, 1).

m = fminbnd(@humps,0.25,1,optimset('Display','off'));fplot(@humps,[0 2]);hold on;plot(m,humps(m),'r*');hold off


Integral of HUMPS

The INTERGRAL function finds the definite integral of HUMPS in a given domain. Here it computes the area in the domain [0.5, 1].

q = integral(@humps,0.5,1);fplot(@humps,[0,2]);title(['Area = ',num2str(q)]);




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Programming MATLAB课程 Program MATLAB atlab MATLAB课程 代码示例 Programming FunctionFunctions


https://www.cda.cn/?seo-luntan
高薪就业·数据科学人才·16年教育品牌

沙发
保罗沃克 在职认证  发表于 2016-3-9 14:53:30
挺有用的,受教了。。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-11 13:55