Title: Flash Gordon and the Mud Men of Matlab
1Flash Gordon and the Mud Men of Matlab
2Quick Exercise (!)
- Consider Polynomial Addition again
- how would you write a program that takes in
two polynomials and irrespective of their sizes
it adds the polynomials together ? Given that the
function length(A) returns the length of a
vector. - Answers on a postcard to dgordon_at_maths.kst.dit.i
e - oh, and while youre here anyhow, if you have a
browser open, please go to the following sites - http//www.the
hungersite.com - http//www.hitsagainsthunger.c
om
3Creating Programs
C
function out program(inputs) PROGRAM ltcodegt
4Know Thyself
- Where am I ?
- pwd
- Get me onto the hard disk
- cd C
- Where am I now ?
- pwd
- Get me to where I know
- cd ..
5Quick Answer (!)
function c mypoly(a,b) MYPOLY Add two
polynomials of variable lengths
mypoly(a,b) add the polynomial A to the
polynomial B, even if they are of
different length Author Damian Gordon
Date 3/5/2001 Mod'd x/x/2001 c
zeros(1,length(b) - length(a)) a zeros(1,
length(a) - length(b)) b
6Recursion
- function b bart(a)
- BART The Bart Simpson program writes on the
blackboard - program, Bart writes the message a few
times - and then goes home to see the Simpsons
- if a 1
- disp('I will not....')
- else
- disp('I will not skateboard in the halls')
- bart(a - 1)
- end
7Curve Fitting
- What is the best fit ?
- In this case least squares curve fit
- What curve should be used ?
- It depends...
8POLYFIT Curve Fitting
- polyfit(x,y,n) - fit a polynomial
- x,y - data points describing the curve
- n - polynomial order
- n 1 -- linear regression
- n 2 -- quadratic regression
9Curve Fitting Example
- x 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1
- y -.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56
9.48 9.30 11.2 - polyfit(x,y,n)
- n 1
- p 10.3185 1.4400
- n 2
- p -9.8108 20.1293 -0.0317
- y -9.8108x2 20.1293x - 0.0317
10Curve Fitting Example
- xi linspace(0,1,100)
- z polyval(p,xi)
- plot(x,y,'o',x,y,xi,z,'')
11Interpolation - 1D
- t interp1(x,y,.75)
- t
- 9.5200
- also
- interp1(x,y,.75,spline)
- interp1(x,y,.75,cubic)
12Interpolation - 2D
- interp2(x,y,Z,xi,yi,TYPE)
TYPE 'nearest' - nearest neighbor
interpolation 'linear' - bilinear
interpolation 'cubic' - bicubic
interpolation 'spline' - spline
interpolation
13Fourier Functions
- fft
- fft2
- ifft
- ifft2
- filter
- filter2
- fftshift
- Fast fourier transform
- 2-D fft
- Inverse fft
- 2-D Inverse fft
- Discrete time filter
- 2-D discrete tf
- shift FFT results so -ve freqs appear first
14Tensors
- See Programs
- Tensors
- Tensors.html
153D Graphics
- T 0pi/5010pi
- plot3(sin(t), cos(t), t)
163D Graphics
- title('Helix'), xlabel('sin(t)'),
- ylabel('cos(t)'), zlabel('t')
- grid
173D Graphics
- Rotate view by elevation and azimuth
- view(az, el)
- view(-37.5, 60)