CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Wiki > Runge Kutta (Matlab)

Runge Kutta (Matlab)

From CFD-Wiki

Jump to: navigation, search
% script file for initial value problems 
% uses Matlab ODE45 - Runge-Kutta method 

clear all;
close all;

% specification of Eta 
eta_low=0.0;
eta_high=10.0; 


eta_cal = [eta_low eta_high];  % array of start and finish points 


finit = [0.0 0.0 0.3320];      % initial values  for f fp fpp

[eta f ] = ode45('state',eta_cal,finit); 
[eta f] 


figure;
plot(eta,f);

figure;

plot(eta,f(:,2),'r') % only interested in velocity profile 



l=true;
a_l=0;
a_u=2;

while (l)
    a=(a_l+a_u)/2;
    finit = [0.0 0.0 a];      % initial values  for f fp fpp

[eta f ] = ode45('filename',eta_cal,finit); %
[eta f] ;

if(abs(1-f(length(f),2))>0.1)
    if(f(length(f),2)>1)
        a_u=(a_l+a_u)/2;
    else
        a_l=(a_l+a_u)/2;
    end
else
    l=false;
end
hold on;
plot(eta,f(:,2)) % only interested in velocity profile 


end


% Contents of filename
%function initial = filename(t,f) 
%initial = [ f(2) , f(3) , -0.5*f(1)*f(3)]'; 

My wiki