Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

Subroutine predictor corrector

$
0
0
Hello everyone!!! I'm writing because I should write this subroutine:

Given the Cauchy problem



write a subroutine for the calculation of its solution using the predictor corrector method in 5 steps (k = 4), according to the PECE scheme, with fixed step.

for the initiation values use the Matlab routine ode45.

So, I have this program but I need of to do some tests but I don't understand what kind of functions I should use...so, you can give me an example of tests that can I do? This is the program:

 % The function calculates the solution of the Cauchy problem
% y'=f(t,y)
% y()=y0
  % takes as input a function, the initial condition, the extremes of the  %integration interval and the width of interval


   function [t,y]=pece(fty,y0,x0,xn,h) 
t=0;         
p=(xn-x0)/h;     
n=length(y0);
  for i=1:p+1
    t(i)=x0+(i-1)*h;        

  y=zeros(1,n);          
f=zeros(3,n);
  
                   

 for i=1:4
    f(i,:)=feval(fty,t(i),y0);   
[t0,m_i]=ode45(fty,[t(1) t(2) t(3) t(4)],y0); 

  y(1:4,:)=m_i(1:4,:);

  mi=m_i(4,:);
  for i = 4:p 
        fnew= feval (fty, t0(4), mi); 
        m_i0=mi+(h/24)*(55*fnew-59*f(3,:)+37*f(2,:)-9*f(1,:));
        f_i0= feval (fty, t0(4)+h, m_i0); 
        mi= mi+(h/24)*(9*f_i0+19*fnew-5*f(3,:)+f(2,:));
        f(1,:) = f(2,:);      
        f(2,:) = f(3,:);       
        f(3,:) = fnew; 
        t0 = t0 + h;
        y(i+1,:)= mi;     
end

  end



Sorry for my mistakes...but I am Italian!!!! Thanks in advance!!!!

Viewing all articles
Browse latest Browse all 2703

Trending Articles