How to plot the graph for the given RK 4th order step method
Show older comments
syms t x
g=(13950-x)/18.75
f=@(t,x) eval(g);
x0=560;
t0=0;
t=15;
h=1;
for c=1:15
k1=h*f(t0,x0);
k2=h*f(t0+(h/2),x0+(k1/2));
k3=h*f(t0+(h/2),x0+(k2/2));
k4=h*f(t0+h,x0+k3);
x=x0+(1/6)*(k1+(2*k2)+(2*k3)+k4);
fprintf('x= %0.4f \n',x)
t0=t0+h;
x0=x;
end
Answers (1)
f=@(t,x)(13950-x)/18.75;
x0=560;
t0=0;
t=15;
h=1;
X(1) = x0;
T(1) = t0;
for c=1:15
k1=h*f(t0,x0);
k2=h*f(t0+(h/2),x0+(k1/2));
k3=h*f(t0+(h/2),x0+(k2/2));
k4=h*f(t0+h,x0+k3);
x=x0+(1/6)*(k1+(2*k2)+(2*k3)+k4);
%fprintf('x= %0.4f \n',x)
t0=t0+h;
x0=x;
X(c+1) = x0;
T(c+1) = t0;
end
hold on
plot(T,X)
syms x(t) t
eqn = diff(x,t) == (13950-x)/18.75;
cond = x(0) == 560;
solx = dsolve(eqn,cond)
fplot(solx,[0 15])
hold off
grid on
Categories
Find more on Networks 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!

