matlab 欧拉法程序错误程序:欧拉法:function [x,y] = eular_f (f,xint,yint,xfinal,n)h = (xfinal-xinit)/n;x = [xinit zeros(1,n)];y = [yinit zeros(1,n)];for i = 1:nx(i+1) = x(i)+h;y(i+1) = y(i)+h*f(x(i),y(i));endend改进的欧拉法:func

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/03 01:32:03
matlab 欧拉法程序错误程序:欧拉法:function [x,y] = eular_f (f,xint,yint,xfinal,n)h = (xfinal-xinit)/n;x = [xinit zeros(1,n)];y = [yinit zeros(1,n)];for i = 1:nx(i+1) = x(i)+h;y(i+1) = y(i)+h*f(x(i),y(i));endend改进的欧拉法:func
xUNA~!م)ݨhJ/#h..Q hQ4@lZ ]v{+xff[ 21ig|L15a~x? Ԋ󴚯/FhzANX7\b[h: Swg\K7%B$++VA)ñs C=>3GYA\j$ҥ w zgVb4ǰ2 +ڋH;ʑ!"gR=}ǐ#͐9D8+lRwml}ΐ,12 1y)FMZú1A]+]wvh^mloAy=(s?•M.ٍ&HUkZWGKn&Ä%ۙԝL 6OI*Ґ!aϹc;.\vfMi(: 5|C䄯]ux>B%nrt>oHvW8]s%)v' ^ 깿35nчMAU+Ot=G8*mO`

matlab 欧拉法程序错误程序:欧拉法:function [x,y] = eular_f (f,xint,yint,xfinal,n)h = (xfinal-xinit)/n;x = [xinit zeros(1,n)];y = [yinit zeros(1,n)];for i = 1:nx(i+1) = x(i)+h;y(i+1) = y(i)+h*f(x(i),y(i));endend改进的欧拉法:func
matlab 欧拉法
程序错误
程序:欧拉法:
function [x,y] = eular_f (f,xint,yint,xfinal,n)
h = (xfinal-xinit)/n;
x = [xinit zeros(1,n)];
y = [yinit zeros(1,n)];
for i = 1:n
x(i+1) = x(i)+h;
y(i+1) = y(i)+h*f(x(i),y(i));
end
end
改进的欧拉法:
function
[x,y] = eular_modified(f,xinit,yinit,xfinal,n)
h = (xfinal-xinit)/n;
x = [xinit zeros(1,n)];
y = [yinit zeros(1,n)];
for i = 1:n
x(i+1) = x(i)+h;
ynew = y(i)+h*f(x(i),y(i));
y(i+1) = y(i)+(h/2)*(f(x(i),y(i))+f(x(i+1),ynew));
end
end
在MATLAB的Editor中调用以上两个函数,输入:
f = @(x,y) 1/x^2-y/x;
g = @(x) (log(x)+1)/x;
xe = [1:0.05:2];
ye = g(xe);
%Call functions
[x1,y1] = eular_f(f,1,2,0.05,20);
[x2,y2] = eular_modified(f,1,2,0.05,20);
%Plot
plot(xe,ye,’k-’,x1,y1,’k-.’,x2,y2,’k:’)
xlabel(‘x’)
ylabel(‘y’)
legend(‘Analytical’,’Forward’,’Modified’)
axis([1 2 1 1])
%Estimate errors
error1 = [‘Forward
error.’
num2 str-100*(ye(end)-y1(end)/ye(end) ’%’)];
error2 = [‘Modified
error.’
num2 strl-100*lye(end)-yz(end)/ye(end) ’%’];
error = {error1,error2};
text(0.04,1.06,error)
结果显示?plot(xe,ye,’k-’,x1,y1,’k-.’,x2,y2,’k:’)
|
Error:Missing variable or function.
请问哪儿出错了,该怎么修改啊?

matlab 欧拉法程序错误程序:欧拉法:function [x,y] = eular_f (f,xint,yint,xfinal,n)h = (xfinal-xinit)/n;x = [xinit zeros(1,n)];y = [yinit zeros(1,n)];for i = 1:nx(i+1) = x(i)+h;y(i+1) = y(i)+h*f(x(i),y(i));endend改进的欧拉法:func
1/函数参数并不对应,函数内部的变量名与参数名不一致,看xinit与xinit,yinit与yinit
2/函数表达式有点小问题,g = @(x) (log(x)+1)/x;乘除的时候,是向量的话就应该换成点乘除
其他没有了