why my graph is not showing any thing ?

1 view (last 30 days)
suketu vaidya
suketu vaidya on 21 Nov 2020
Commented: suketu vaidya on 21 Nov 2020
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

Answers (1)

KSSV
KSSV on 21 Nov 2020
Edited: KSSV on 21 Nov 2020
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 Comments
KSSV
KSSV on 21 Nov 2020
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 on 21 Nov 2020
i want to solve ranga kutta 3rd order eqvation

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!