facing problem to function calling
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
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일
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
2020년 11월 9일
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!