why my graph is not showing any thing ?

2 次查看(过去 30 天)
function Lab02
h = 0.001;
p=1;
x=0:p:0.5;
t = 0:h:0.5;
y = [0];
for i = 1:length(p)-1
k1=f(x(i),y(i));
k2=f(x(i)+1/2*h,y(i)+1/2*k1*h);
k3=f(x(i)+h,y(i)-k1*h+2*k2*h);
y(i+1)=y(i)+h/6*(1*k1+4*k2+1*k3);
end
plot(x,y);
hold on
end
%analitycal solution
function dy=f(x,y)
syms y(x);
ode=(diff(y(x),x,2))+10*y(x) +sin(100*pi*x)==0;
ySol(x) = dsolve(ode);
c1=1;
c2=1;
dy=c2*sin(3.1623*x)+c1*cos(3.1623*x)+(sin(100*pi*x))/((10000*pi*pi)-10);
end

回答(1 个)

KSSV
KSSV 2020-11-21
编辑:KSSV 2020-11-21
Check this line:
p = 1 ;
x=0:p:0.5;
The above shpuld be repalced with proper value p. Now it will create only one value i.e. x = 0. You should repalce this line with the appropriate stpe size p.
  3 个评论
KSSV
KSSV 2020-11-21
Did you consider this line:
for i = 1:length(p)-1
Still your code is a mess. What exactly you are trying?
suketu vaidya
suketu vaidya 2020-11-21
i want to solve ranga kutta 3rd order eqvation

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by