MATLAB Ex 48 n n Greek Letters Subscripts
MATLAB 程式設計 Ex 4_8 n n Greek Letters, Subscripts, and Superscripts alpha beta gamma delta epsilon phi theta kappa lambda mu nu pi rho sigma tau xi zeta Gamma Pi Delta. . . . n n Θ 1 is coded with theta_1 Θ 12 is coded with theta {12} Θ 10 is coded with theta ^{10} text(10, . 5, ’Hi’);
MATLAB 程式設計 Ex 4_9 Roots n Roots of a Polynomial n n % find the roots of a polynomial p=[1, 2, -13, -14, 24]; r=roots(p) Find the polynomial from the roots n n r=[1, 2, 3]; p=poly(r)
MATLAB 程式設計 First Derivative of a polynomial array n n a=[1, 1, 1, 1] ap=polyder(a)
MATLAB 程式設計 Ex 4_10 Evaluate a Polynomial n If you have an array of x-values and you want to evaluate a polynomial at each one n n n n % define the polynomial a=[1, 2, -13, -14, 24]; % load the x-values x=-5: . 01: 5; % evaluate the polynomial y=polyval(a, x); % plot it plot(x, y)
MATLAB 程式設計 Ex 4_11 Fitting Data to a Polynomial n n n n n x=linspace(0, pi, 50); % make a sine function with 1% random error on it f=sin(x)+. 01*rand(1, length(x)); % fit to the data p=polyfit(x, f, 4); % evaluate the fit g=polyval(p, x); % plot fit and data together plot(x, f, ’r*’, x, g, ’b-’)
MATLAB 程式設計 Ex 4_12 Using fzero n n n function f=fz(x) % evaluate the function fz(x) whose % roots are being sought f=exp(-x)-x; %******************** % Here is the matlab code that uses fz. m to find % a zero of f(x)=0 near the guess x=. 7 % Note that the @ sign is used to tell Matlab that % the name of an M-file is being passed into fzero %******************** x=fzero(@fz, . 7)
- Slides: 7