facing problem to function calling
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
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 commentaires
Rik
le 9 Nov 2020
What are you trying to do? Is this all in 1 file? Did you mean for these functions to be nested functions? Your end keywords don't seem to match up.
suketu vaidya
le 9 Nov 2020
Rik
le 9 Nov 2020
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.
Réponses (0)
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!