I need your help. y'(t) = -30*y+30*t^2+2*t; y(0)=1, & exact solution is y(t)=e^-30*x +x^2. i can't understand what is different b/w kr4 plotting & its error . i need both graph n error please send me code.
Show older comments
function rungekutta123
h = 0.05;
t = 0;
w = 1;
fprintf('Step 0: t = %12.8f, w = %12.8f\n', t, w);
for i=1:50
k1 = h*f(t,w);
k2 = h*f(t+h/2, w+k1/2);
k3 = h*f(t+h/2, w+k2/2);
k4 = h*f(t+h, w+k3);
w = w + (k1+2*k2+2*k3+k4)/6;
t = t + h;
fprintf('Step %d: t = %6.4f, w = %18.15f\n', i, t, w);
end
%%%%%%%%%%%%%%%%%%
function v = f(t,y)
v = -30*y+30*t^2+2*t;
2 Comments
jamila nizamani
on 2 Feb 2014
Image Analyst
on 2 Feb 2014
Please read this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup and fix your formatting.
Accepted Answer
More Answers (1)
Nurcan
on 22 Apr 2024
0 votes
y(t)=f(t, y(t)) y(t0)=y0 tE[t0, T] f(t,y)=-y/(2*t)+t^2 t0=1 T=2 y0=1
Categories
Find more on Programming 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!