Mat 275 Modern Differential Equations

Mat 275 Modern Differential Equations

<p> Mat 275 Modern Differential Equations Dr. Firozzaman Department of Mathematics and Statistics Arizona State University Lab 2 due on August 1, 2006</p><p>Examples: Try all (Do not print, you need to print solutions of the homework problems only) Files containing MATLAB commands are called m-files and have a .m extension. They are two types:</p><p> a) A script is simply a collection of MATLAB commands gathered in a single file. The value of the data created in a script is still available in the command window after execution. </p><p>Example 1. Script file save as plot1.m (type as a file and save)</p><p>Plotting a function y  22e x / 5  5x  25 using window [0, 5]x[-5, 10]</p><p> x = 0:1:5; y = 22*exp(x./5)-5*x-25; plot(x,y,’r-’, ’LineWidth’,2); axis([0,5,-5,10]); grid on; title(’f(x)=(22 e^(x/5)-5x-25)’); xlabel(’x’); ylabel(’y’); Then run your program and get the plot on MATLAB prompt by typing >>plot1</p><p> b) A function is similar to a script, but can accept and return arguments. Unless otherwise specified any variable inside in a function is local to the function and not available in the workspace. A function invariably starts with the command function output = function_name(input)</p><p>Example 2. Script + Function (two separate files)</p><p> i) Save the file as function1.m</p><p> function y=function1(x) y = 22*exp(x./5)-5*x-25;</p><p> ii) Save the file as plot2.m x = 0:1:5; y = feval(@function1,x); plot(x,y,’r-’, ’LineWidth’,2); axis([0,5,-5,10]); grid on; title(’f(x)=(22 e^(x/5)-5x-25)’); xlabel(’x’); ylabel(’y’); Then run your program and get the plot on MATLAB prompt by typing >>plot2 c) Script + Function (one file) save as plot3.m</p><p> function plot3 x = 0:1:5; y = feval(@function1,x); plot(x,y,’r-’, ’LineWidth’,2); axis([0,5,-5,10]); grid on; title(’f(x)=(22 e^(x/5)-5x-25)’); xlabel(’x’); ylabel(’y’); %------function y=function1(x) y = 22*exp(x./5)-5*x-25;</p><p>Then run your program and get the plot on MATLAB prompt by typing >>plot3</p><p> d) Numerical solution by Euler Method</p><p>As an example consider the initial value problem (IVP)</p><p> dy  2y, y(0)  3 dt Follow the steps:</p><p>>>clear t y >>y(1)=3; t(1)=0; h =0.1; >>f=inline(’2*y’, ’t ’, ’y ’); >>y(2)=y(1)+h*f(t(1),y(1)), t(2)=t(1)+h, >>y(3)=y(2)+h*f(t(2),y(2)), t(3)=t(2)+h, >>y(4)=y(3)+h*f(t(3),y(3)), t(4)=t(3)+h, >>y(5)=y(4)+h*f(t(4),y(4)), t(5)=t(4)+h, >>y(6)=y(5)+h*f(t(5),y(5)), t(6)=t(5)+h, >>[t(:),y(:)] >>plot(t,y);axis tight</p><p>------Homework: You need to print your work and turn in.</p><p>1. Write an m-file to plot the function y  3e2x with suitable x and y values dy 2. Use Euler Method to plot the solution curve of the IVP  t  y, y(0)  1 dt 3. Find eigenvalues and eigenvectors of A = magic(3) (Optional) ------</p><p>Try the following matrix operations. Do not print. >> A=[8, 1,6; 3, 5, 7; 4, 9, 2] >> row1=[8, 1, 6]; row2 =[3, 5, 7]; row3 =[4, 9, 2]; A=[row1; row2; row3] Also try using columns like co1, col2, col3</p><p>Try the following and understand what you get back:</p><p>>>A(2, 3) % coefficient of A in 2nd row , 3rd column >>A(1,:) % first row of A >>A(:,3) % 3rd column of A >>I=eye(3) >>B=magic(3) %can you find what is magic of this matrix? >>C= A+B >>D = A*B >>[S,D]= eig(A) </p><p>%determines the eigenvectors of A (columns of S) and associated eigenvalues (diagonal coefficients of D) note that the eig function has one input and two outputs arguments. </p><p>You may verify eigenvalues and eigenvectors of the problem we have solved in the class (Section 5.2) ------HAVE FUN ------</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us