How to plot the graph for the given RK 4th order step method
古いコメントを表示
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
回答 (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
カテゴリ
ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


