1 / 17

Flash Gordon and the Mud Men of Matlab

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 irrespective of their sizes it adds the polynomials together ? Given that the function length(A) returns the length of a vector.

clovis
Download Presentation

Flash Gordon and the Mud Men of Matlab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Flash Gordonand 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@maths.kst.dit.ie oh, and while you’re here anyhow, if you have a browser open, please go to the following sites : http://www.the hungersite.com http://www.hitsagainsthunger.com

  3. Creating Programs Title : Program.m C: function out = program(inputs) % PROGRAM <code>

  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. 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 Fourier Functions

  14. Tensors • See ‘Programs’ • ‘Tensors’ • ‘Tensors.html’

  15. 3D Graphics T = 0:pi/50:10*pi; 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);

More Related