// Marc Courtright 9/15/02 // numerical_int.sce // a program that uses numerical integration to approximate the area under a function // To run this in Scilab use 'File' then 'Exec'. // global variables M=1; // mass h=2; // step start_time=0; // lower limit total_time=100; // upper limit function[F,vprime,v]=v(M,h,t) if(0<=t<=4) then, F=1,else,F=2,end // set up the step input of F vprime=F/M; // d/dt (function) v=V((i-1),5)+h*vprime; // f(t+h)=f(t)+h*fprime endfunction // declarations and initialization imax=((total_time-start_time)/h) // stopping point for loop index "i" n=imax+1 // initial conditions Vmatrix = matrix(v,n,5); // matrix to store v and vprime V(1,:)=["i ","t ","F(N) ","d/dt v ","v "]; // header for the matrix V(2,:)=[0,0,0,0,0] //initial conditions // calculations for i=1:imax, t=h*i; V(i,1)=i V(i,2)=t V(i,3:5)=v(M,h,t) i=i+1; end; // write to file unix("del c:\temp\numerical_int.text"); write("c:\temp\numerical_int.text", [Vmatrix]);