24小时热门版块排行榜    

查看: 1282  |  回复: 12

北欧的秋天

新虫 (初入文坛)

引用回帖:
8楼: Originally posted by 往前一步走 at 2016-11-02 01:18:51
求分享
...

例?求下列非线性方程组在(0.5,0.5) 附近的数值解。
(1) 建立函数文件myfun.m。
function q=myfun(p)
x=p(1);
y=p(2);
q(1)=x-0.6*sin(x)-0.3*cos(y);
q(2)=y-0.6*cos(x)+0.3*sin(y);
(2) 在给定的初值x0=0.5,y0=0.5下,调用fsolve函数求方程的根。
x=fsolve('myfun',[0.5,0.5]',optimset('Display','off'))
x =
0.6354
0.3734
将求得的解代回原方程,可以检验结果是否正确,命令如下:
q=myfun(x)
q =
1.0e-009 *
0.2375?0.2957
可见得到了较高精度的结果。
cite from:http://blog.sina.com.cn/s/blog_56ef652d0100ebew.html
4、fsolve函数解方程
[X,FVAL,EXITFLAG,OUTPUT,JACOB]=FSOLVE(FUN,X0,...) returns the
Jacobian of FUN at X.

Examples
FUN can be specified using @:
x = fsolve(@myfun,[2 3 4],optimset('Display','iter'))

where myfun is a MATLAB function such as:

function F = myfun(x)
F = sin(x);

FUN can also be an anonymous function:

x = fsolve(@(x) sin(3*x),[1 4],optimset('Display','off'))

If FUN is parameterized, you can use anonymous functions to capture the
problem-dependent parameters. Suppose you want to solve the system of
nonlinear equations given in the function myfun, which is parameterized
by its second argument c. Here myfun is an M-file function such as

function F = myfun(x,c)
F = [ 2*x(1) - x(2) - exp(c*x(1))
-x(1) + 2*x(2) - exp(c*x(2))];

To solve the system of equations for a specific value of c, first assign the
value to c. Then create a one-argument anonymous function that captures
that value of c and calls myfun with two arguments. Finally, pass this anonymous
function to FSOLVE:

c = -1; % define parameter first
x = fsolve(@(x) myfun(x,c),[-5;-5])

发自小木虫Android客户端
11楼2016-11-02 08:27:50
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

北欧的秋天

新虫 (初入文坛)

引用回帖:
2楼: Originally posted by BLITZ0315 at 2016-11-01 23:10:43
前边有一个判断语句,执行你说的语句时,i=j,应该是这样

三克油,懂了

发自小木虫Android客户端
12楼2016-11-02 08:28:32
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
送红花一朵
13楼2016-11-03 21:08:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 北欧的秋天 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见