# Alternative Mathematics using MATLAB 7

### Gunnar Backstrom (view profile)

13 Mar 2003 (Updated )

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

ex193.m
```% ex193.m:  Euler Numerical Solution to y'+x^2*y=1+x^3
clear all
F= inline('1+ X.^3- X.^2.*Y', 'X', 'Y');
X(1)=input('x1=  (e.g. 0) ');  Y(1)=input('y1=  (e.g. 2) ');
n=300;  h=0.01;
for i=1:n
dy=F( X(i), Y(i))*h;
X(i+1)=X(i)+h;
Y(i+1)=Y(i)+dy;
end
figure(1),   plot(X,X, 'b',  X,Y),  grid on,  axis([0 n*h 0 3]),  hold on
title('Solution to dy/dx+x^2*y=1+x^3')
% Add direction field to figure(1) for comparison
xmax=4;  delx=xmax/30;
ymax=3;  dely=ymax/30;
[Xm,Ym]=meshgrid(0:delx:xmax, 0:dely:ymax);
Dx=Xm-Xm+1;				% Unit x-components of arrows
Dy=F(Xm,Ym);				% Compute y-components
L=sqrt(Dx.^2+ Dy.^2);			% Initial length of [Dx Dy]
L=L+1e-10;					% Add small number to avoid L=0
Dx1=Dx./L;  Dy1=Dy./L;		% Unit length for all arrows
figure(1),  quiver(Xm,Ym,  Dx1,Dy1, 'g.'),  grid on,  hold off
```