how to create a matlab code for runge kutta 4th order using implicit function..here i hv tried but it is showing error in line 16 as In an assignment A(I) = B, the number of elements in B and I must be the same.
Show older comments
function [ t,x] = Untitled2(h)
%UNTITLED2 Summarx of this function goes here
% Detailed etplanation goes here
t = 0:h:3;
u=t.^2;
x(1) = 0;
fx = @(t,x) 2*u;
for i=1:(length(t)-1)
k1 = fx(t(i),x(i));
k2 = fx(t(i)+0.5*h,x(i)+0.5*h*k1);
k3 = fx(t(i)+0.5*h,x(i)+0.5*h*k2);
k4 = fx(t(i)+h,x(i)+k3*h);
x(i+1) = x(i) + (1/6)*(k1+2*k2+2*k3+k4)*h;
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations 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!