解决Matlab代码中的错误

时间:2018-06-27 08:30:26

标签: matlab physics

我需要使用fsolve求解MHD冲击波情况的这六个方程式(https://en.wikipedia.org/wiki/Shocks_and_discontinuities_(magnetohydrodynamics))。有6个未知变量,其值需要存储在z中。但是,由于我是新手,所以我在Matlab中遇到了这些错误,并且不知道如何纠正它们。 以下是我的eqn.m功能文件-

function [f1,f2,f3,f4,f5,f6]= eqn(x)
global rho1 vx1 by1 w p1 vy1 bx1;
f1=(x(2)*x(3))-(rho1*vx1);
f2=x(1)+(x(2)*x(3)^2)+(x(6)*x(6)*0.5/w)-p1-(rho1*vx1*vx1)-by1*by1*0.5/w;
f3=(x(2)*x(3)*x(4)-x(5)*x(6)/w)-rho1*vx1*vy1+bx1*by1/w;
f4= x(5)-bx1;
f5=x(3)*x(6)-x(5)*x(4)-vx1*by1+vy1*bx1;
f6=x(2)*x(3)*(0.5*(x(3)^2+x(4)^2) +2.5*x(1)/x(2)) +x(3)*(x(6)^2)/w -x(5)*x(6)*x(4)/w - rho1*vx1*(0.5*(vx1^2+vy1^2) +2.5*p1/rho1) -(vx1*by1^2)/w + bx1*by1*vy1/w;



end

这是我的基本代码-

 disp("Assume the shock propogates in the x direction");
 p1=input('Upstream pressure-');
 rho1=input('Upstream density-');
 vx1=input('Upstream velocity along x axis-');
 vy1=input('Upstream velocity along y axis-');
 bx1=input('Upstream magnetic field along x axis-');
 by1=input('Upstream magnetic field along y axis-');

 w=1.25663706144e-06;

 y=[2*p1,4*rho1,0.5,0.5,3*bx1,3*by1];   %intial guess

 fun=@eqn;
 z=fsolve(fun,y);

 disp z;

我得到的错误-

 Error using  / 
 Matrix dimensions must agree.

 Error in eqn (line 4)
 f2=x(1)+(x(2)*x(3)^2)+(x(6)*x(6)*0.5/w)-p1-(rho1*vx1*vx1)-by1*by1*0.5/w;

 Error in fsolve (line 230)
        fuser = feval(funfcn{3},x,varargin{:});

 Error in MHD (line 15)
 z=fsolve(fun,y);

Caused by:
    Failure in initial objective function evaluation. FSOLVE cannot continue.

0 个答案:

没有答案