24小时热门版块排行榜    

CyRhmU.jpeg
查看: 2911  |  回复: 1

zhaoxyah

铁杆木虫 (著名写手)

[求助] 用matlab解非线性方程组加for循环语句的问题已有1人参与

用matlab解非线性方程组,现在问题出在加for 循环语句上,想让其中一参数thita变化来求非线性方程组的解,但是for循环语句加进去之后循环不了,求指教,谢谢



function solve_noneqs2
clear all;clc
format long
x0=[0.8 -5 0.1];
[x fval]=fsolve(@objfun,x0)

function f=objfun(x)

for i=1:10:81

thita=i*3.14/180.0;
gam=0.8;
gama=gam/(cos(thita)+gam*(1-cos(thita)));  
nn=0;

mie=1836.0*4.0;
miu=1.0/mie;
tie=0.01;
rou=0.2;
uiy0=-0.01;
e0=-0.01;
f(1)=(1+x(1))*x(3)-(1-gama)*sqrt(2*mie*pi)*exp(x(2))/(1+erf(sqrt(-x(2))));
f(2)=gama*x(3)/(1-gama)-x(1)*sqrt(nn*nn-2*mie*x(2))/(1+x(1));
f(3)=(1+erf(sqrt(-x(2)))+2*exp(x(2)))/(1+erf(sqrt(-x(2))))...
+(-x(1)/(miu*nn*nn-2*x(2)))-(1-rou*uiy0*sin(thita)/e0)/(x(3)*x(3)-tie);
end
回复此楼

» 收录本帖的淘帖专辑推荐

材料学

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

月只蓝

主管区长 (职业作家)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
zhaoxyah: 金币+30, ★★★★★最佳答案 2015-01-28 14:35:23
CODE:
function solve_noneqs2
clear all;clc
format long
global thita
x0=[0.8 -5 0.1];
for i=1:10:81

thita=i*3.14/180.0;
[x fval]=fsolve(@objfun,x0)
end

function f=objfun(x)

global thita
gam=0.8;
gama=gam/(cos(thita)+gam*(1-cos(thita)));  
nn=0;

mie=1836.0*4.0;
miu=1.0/mie;
tie=0.01;
rou=0.2;
uiy0=-0.01;
e0=-0.01;
f(1)=(1+x(1))*x(3)-(1-gama)*sqrt(2*mie*pi)*exp(x(2))/(1+erf(sqrt(-x(2))));
f(2)=gama*x(3)/(1-gama)-x(1)*sqrt(nn*nn-2*mie*x(2))/(1+x(1));
f(3)=(1+erf(sqrt(-x(2)))+2*exp(x(2)))/(1+erf(sqrt(-x(2))))...
+(-x(1)/(miu*nn*nn-2*x(2)))-(1-rou*uiy0*sin(thita)/e0)/(x(3)*x(3)-tie);

计算结果:
CODE:
Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>


x =

   0.018846681984329  -3.072831795928832   0.982314870246254


fval =

  1.0e-013 *

  -0.044408920985006   0.039968028886506  -0.595079541199084


Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>


x =

   0.018855956779978  -3.075528224076973   0.965321046112058


fval =

  1.0e-013 *

  -0.004440892098501   0.004440892098501  -0.217603712826531


Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>


x =

   0.019558737227657  -3.052541979758258   0.948120266395786


fval =

  1.0e-014 *

                   0  -0.355271367880050  -0.710542735760100


Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>


x =

   0.021135332349230  -2.999752526247271   0.931165724462005


fval =

  1.0e-014 *

   0.044408920985006  -0.266453525910038  -0.177635683940025


Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>


x =

   0.024008638352036  -2.909615150811957   0.914786597776324


fval =

  1.0e-015 *

   0.666133814775094  -0.888178419700125  -0.222044604925031


Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>


x =

   0.029146638299003  -2.768619210304688   0.899037628244904


fval =

  1.0e-014 *

                   0  -0.177635683940025   0.022204460492503


Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>


x =

   0.039085890345084  -2.550572682027647   0.883288524779719


fval =

  1.0e-015 *

  -0.222044604925031                   0   0.444089209850063


Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>


x =

   0.062780505811200  -2.194272858045788   0.864731643692605


fval =

  1.0e-014 *

  -0.022204460492503   0.177635683940025                   0


Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>


x =

   0.167507062022604  -1.476415003357842   0.830027082398914


fval =

  1.0e-015 *

  -0.111022302462516                   0   0.222044604925031

MATLAB、MS小问题、普通问题请发帖求助!时间精力有限,恕不接受无偿私信求助。
2楼2015-01-27 16:17:35
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 zhaoxyah 的主题更新
信息提示
请填处理意见