No BSD License  

Highlights from
Alternative Mathematics using MATLAB 7

image thumbnail

Alternative Mathematics using MATLAB 7


Gunnar Backstrom


13 Mar 2003 (Updated )

Self-instructive text on undergraduate algebra, statistics, differential and integral calculus.

% ex201a.m: Euler's solution to y''= -cy					       
clear all
c=1.0;						% Value for k/m
n=1000;		h=0.01;
while 1==1						% Forever true
   T(1)=0;						% Start time, SI units ...
   Y(1)=input('y1=   (e.g. 0) ');				% Initial position
   Yp(1)=input('yp1=  (e.g. 1) ');			% Initial velocity
      if  (Y(1)==0) & (Yp(1)==0),  break,  end	% & means AND
   for i= 1: n-1
      T(i+1)= i*h;
      [dydt dypdt]=spring( T(i), Y(i), Yp(i));
      Y(i+1)=Y(i)+ dydt*h;
      Yp(i+1)=Yp(i)+ dypdt*h;			% Y-prime
figure(1),  plot(T,Y,  T,Yp),  grid on,  title('y"= -cy')
   xlabel('time'),  legend('Y', 'Yp')	
   Yex=Yp(1)*sin(T)+ Y(1)*cos(T);
figure(2),  plot(T,Y,   T,Yex),  grid on,  title('y"=-cy')
   xlabel('time'),  legend('Euler', 'Exact')

Contact us