Info
この質問は閉じられています。 編集または回答するには再度開いてください。
facing problem to function calling
2 ビュー (過去 30 日間)
古いコメントを表示
function [x,y1]=exlicit(f1)
h =1;
x = -pi:h:pi;
n = 0:1:10;
y1 = [0];
for i=1:n
x(i+1)=x(i)+h;
y1(i+1)=y1(i)+h*f1(x(i),y1(i));
end
end
%heun's method
function [x,y1]=heun(f1)
h =1;
x = -pi:h:pi;
n = 0:1:10;
y1 = [0];
for i=1:n
x(i+1)=x(i)+h;
ynew=y1(i)+h*(f1(x(i),y1(i)));
y1(i+1)=y1(i)+(h/2)*(f1(x(i+1),y1(i))+h*f1(x(i+1),ynew));
end
end
%euler implicit method
function [x,y1]=implicit(f1)
h =1;
x = -pi:h:pi;
n = 0:1:10;
y1 = [0];
for i=1:n
x(i+1)=x(i)+h;
ynew=y1(i)+h*(f1(x(i),y1(i)));
y1(i+1)=y1(i)+h*f1(x(i+1),ynew);
end
end
%Runge Kutta 4th order method:
function [x,y1]=Runge(f1)
h =1;
x = -pi:h:pi;
n = 0:1:10;
y1 = [0];
for i=1:n
k1=f1(x(i),y1(i));
y1(i+1)=y1(i)+(h*k1)
end
end
function dy =f1(x,y1)
d=50;
c1=-1-d^2/(d^2+1);
x=0:0.01:10;
dy=c1*exp(-d*x)+d*sin(x)/(d^2+1)+d^2*cos(x)/(d^2+1);
end
%plot
%call function
[x2,y2]=exlicit(f1);
[x3,y3]=heun(f1);
[x4,y4]=implicit(f1);
[x5,y5]=Runge(f1);
plot(x2,y2,'g-',x3,y3,'b',x4,y4,'m-',x5,y5,'r')
hold on
end
3 件のコメント
Rik
2020 年 11 月 9 日
Well, you will first have to fix what is inside a function and what is outside of it. Pay attention to m-lint: those squiggly lines under your code should all be gone. It will give you advice how to solve them.
回答 (0 件)
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!