Hello,
I would like to run the runge kutta method within a loop for various values for 'p'. My problem is saving the array of results (for outputs=Y) in the workspace for each loop/increment of 'p'. Please assist. Thank you
function [x, y] = FunctionBeta_Executor(F)for p=1:0.2:5h=0.15; % step size (smaller step size gives more accurate solutions)
x = 0:h:3; % x space
y = zeros(length(x):1); % Memory allocation
y(1) = 0; % initial condition
F = @(x, y)(x+y+p);for i=1:(length(x)-1) % i=1:(length(x)-1) % calculation loop
k1 = F(x(i),y(i)); k2 = F(x(i)+0.5*h,y(i)+0.5*h*k1); k3 = F((x(i)+0.5*h),(y(i)+0.5*h*k2)); k4 = F((x(i)+h),(y(i)+k3*h)); y(i+1) = y(i) + (1/6)*(k1+2*k2+2*k3+k4)*h; % main equation
endfigure, plot(x, y) % To see the solution results
endend
Best Answer