Runge-Kutta method
2 views (last 30 days)
Show older comments
Write the Matlab / C++ routine of Runge-Kutta method of Order four for the following problem
y^'-y=3x^2,y(0)=4
for the range 0.1≤x≤0.5, by taking h=0.025.
Note: Please give proper answer, this question is fro numerical analysis.
3 Comments
Steven Lord
on 6 Aug 2020
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Answers (1)
esat gulhan
on 15 Aug 2020
%RUNGE KUTTA METHOD OF ORDER FOUR
clc;clear; % Clears the screen
h=0.025; % step size
x = 0.1:h:0.5;
y = zeros(1,length(x));
y(1) = 4; % initial condition,y(1) is y(0) value
F_xy = @(x,y) 3*x^2+y; % function
for i=1:(length(x)-1) % calculation loop
k_1 = F_xy(x(i),y(i));
k_2 = F_xy(x(i)+0.5*h,y(i)+0.5*h*k_1);
k_3 = F_xy((x(i)+0.5*h),(y(i)+0.5*h*k_2));
k_4 = F_xy((x(i)+h),(y(i)+k_3*h));
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation
end
for i=1:(length(x))
fprintf('%12.5f',x(i),y(i));fprintf('\n')
end
You should use ode45 formula in order to this formula, you can solve this problem with dsolve.
1 Comment
John D'Errico
on 15 Aug 2020
Please don't do homework assignments for people. This teaches them nothing, except how to get someone else to do their work for them.
See Also
Categories
Find more on Get Started with MATLAB 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!