Flash Gordon and the Mud Men of Matlab - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Flash Gordon and the Mud Men of Matlab

Description:

Flash Gordon and the Mud Men of Matlab Quick Exercise (!) Consider Polynomial Addition again : how would you write a program that takes in two polynomials and ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 18
Provided by: dgor
Category:
Tags: flash | gordon | matlab | men | mud | simpsons

less

Transcript and Presenter's Notes

Title: Flash Gordon and the Mud Men of Matlab


1
Flash Gordon and the Mud Men of Matlab

2
Quick 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

3
Creating Programs
  • Title Program.m

C
function out program(inputs) PROGRAM ltcodegt
4
Know 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 ..

5
Quick 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
6
Recursion
  • 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

7
Curve Fitting
  • What is the best fit ?
  • In this case least squares curve fit
  • What curve should be used ?
  • It depends...

8
POLYFIT 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

9
Curve 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

10
Curve Fitting Example
  • xi linspace(0,1,100)
  • z polyval(p,xi)
  • plot(x,y,'o',x,y,xi,z,'')

11
Interpolation - 1D
  • t interp1(x,y,.75)
  • t
  • 9.5200
  • also
  • interp1(x,y,.75,spline)
  • interp1(x,y,.75,cubic)

12
Interpolation - 2D
  • interp2(x,y,Z,xi,yi,TYPE)

TYPE 'nearest' - nearest neighbor
interpolation 'linear' - bilinear
interpolation 'cubic' - bicubic
interpolation 'spline' - spline
interpolation
13
Fourier 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

14
Tensors
  • See Programs
  • Tensors
  • Tensors.html

15
3D Graphics
  • T 0pi/5010pi
  • plot3(sin(t), cos(t), t)

16
3D Graphics
  • title('Helix'), xlabel('sin(t)'),
  • ylabel('cos(t)'), zlabel('t')
  • grid

17
3D Graphics
  • Rotate view by elevation and azimuth
  • view(az, el)
  • view(-37.5, 60)
Write a Comment
User Comments (0)
About PowerShow.com