作业帮 > 综合 > 作业

求高手看看这个MATLAB的解方程的程序错在哪里?

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/05/14 12:10:51
求高手看看这个MATLAB的解方程的程序错在哪里?
>> clear all,clc
syms a x pi;
L1=a*pi*x-a*pi^3*x^3/6-x;
L2=a*pi(1-x^2/2)-1;
[x,a]=fsolve(L1,L2)
出错提示为:
Error using ==> subsindex
Function 'subsindex' is not defined for values of class 'sym'.
求高手看看这个MATLAB的解方程的程序错在哪里?
先建立M文件函数

function F=myfun(x)
F=[x(1)*pi*x(2)-x(1)*pi^3*x(2)^3/6-x(2);
x(1)*pi*(1-x(2)^2/2)-1];
保存该M文件

>> x0=[1,1];
>> options=optimset('Display','iter');
>> x=fsolve(@myfun,x0,options)
Norm of First-order Trust-region
Iteration Func-count f(x) step optimality radius
0 3 9.48321 38.6 1
1 6 1.31319 0.640029 4.95 1
2 9 0.103772 0.265389 0.646 1
3 12 0.0119565 0.181273 0.179 1
4 15 0.00121197 0.131901 0.0588 1
5 18 0.000131 0.0929647 0.0211 1
6 21 1.51703e-005 0.0641496 0.00812 1
7 24 1.98613e-006 0.0438623 0.00338 1
8 27 3.00857e-007 0.0298401 0.00147 1
9 30 5.19838e-008 0.0202531 0.00066 1
10 33 9.84515e-009 0.013731 0.0003 1
11 36 1.96625e-009 0.00930442 0.000137 1
12 39 4.03615e-010 0.0063034 6.26e-005 1
13 42 8.39621e-011 0.00426985 2.87e-005 1
14 45 1.75765e-011 0.00289221 1.31e-005 1
15 48 3.69017e-012 0.00195901 6.03e-006 1
16 51 7.75787e-013 0.0013269 2.77e-006 1
17 54 1.63191e-013 0.000898748 1.27e-006 1
Optimization terminated: relative function value changing by less
than max(options.TolFun^2,eps) and sum-of-squares of function
values is less than sqrt(options.TolFun).
x =
0.3183 0.0019

这里得到的解分别就是你要求解的a和x的值.另外需要说明的是,我设定几个初值的时候,得到的结果都是(a=0.3183, x=0).