Runge-Kutta method

1 次查看(过去 30 天)
Aslam Ali
Aslam Ali 2020-8-6
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 个评论
Aslam Ali
Aslam Ali 2020-8-6
I can't attempt this question because i didn't understand it please if anyone know the answer and code then kinly share it
Steven Lord
Steven Lord 2020-8-6
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.

请先登录,再进行评论。

回答(1 个)

esat gulhan
esat gulhan 2020-8-15
%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 个评论
John D'Errico
John D'Errico 2020-8-15
Please don't do homework assignments for people. This teaches them nothing, except how to get someone else to do their work for them.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by