1 / 16

ENG004 ALGORITHMS & INT. TO PROGRAMMING

ENG004 ALGORITHMS & INT. TO PROGRAMMING. Week 4 “Arrays and Matrix Operations III” Ahmet Anıl Dindar 21.03.2007. The class facts. E-mail address : iku.eng004.01@gmail.com Class web page: http://web.iku.edu.tr/courses/insaat/eng004/. Last week. First Program! Arrays (Matrices)

rumor
Download Presentation

ENG004 ALGORITHMS & INT. TO PROGRAMMING

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. ENG004 ALGORITHMS & INT. TO PROGRAMMING Week 4 “Arrays and Matrix Operations III” Ahmet Anıl Dindar 21.03.2007

  2. The class facts • E-mail address: iku.eng004.01@gmail.com • Class web page: http://web.iku.edu.tr/courses/insaat/eng004/ ENG004.01

  3. Last week • First Program! • Arrays (Matrices) • The user input command : “input” • The arrays in formulas • Trigonometric calculations • Examples: “Gauss Number summation” “Fligth Problem” ENG004.01

  4. This week • More programming... • Accessing elements of arrays and matrices • Element by element matrix operations • Example “Fligth Problem” ENG004.01

  5. Fligth Problem We want to calculate the followings? 1- The duration of the object’s fligth.(Tflight) 2- The highest altitude of the fligth. (ymax) 3- The distance between the origin and landing point. (xmax) PS: 2 weeks later, we will visulize our findings! ENG004.01

  6. Fligth Problem The formulation of the flight problem is: By using this equation we determine the following equations • 1- The duration of the object’s fligth.(tflight) • 2- The highest altitude of the fligth. (ymax) • 3- The distance between the origin and landing point. (xmax) ENG004.01

  7. Let’s re-write the Fligth Problem code The user should enter the initial values into the computer 1- The initial velocity (V0) 2- The horizontal angle (a) 3- The gravity acceleration (g) Then the code should calculate 1- The duration of the object’s fligth.(Tflight) 2- The highest altitude of the fligth. (ymax) 3- The distance between the origin and landing point. (xmax) If OK, Let's start writing the CODE! ENG004.01

  8. The user input lines The Code of the Flight Problem clc,clear,close all v0=input('Please enter the initial velocity : ') alfa=input('Pleae enter the horizontal angle : ') g=input('Please enter the gravity acceleration : ') The computer calculations % The following line calculates the duration of the fligth tflight=2*v0*sin(alfa*pi/180)/g ; Now, Do you think you can calculate the ymax and xmax? ENG004.01

  9. The computer should calculate the xmax and ymax. The Code of the Flight Problem % xmax xmax=v0*cos(alfa*pi/180)*tfligth; % ymax ymax=v0*sin(alfa*pi/180)*tf/2-.5*g*(tf/2)^2; The “;” does not allow the program to display the results in the command window. If you want to see the results, you need new commands : “fpritnf” % let's see the results in the command window fprintf('The highest altitude of the flight is %.2f m \n',ymax) fprintf('The distance of the landing point is %.2f m \n',xmax) ENG004.01

  10. The Code of the Flight Problem Let’s estimate the max values from the x and y series. In order to create the x and y series, we need to create the time series: % time series t=(0:.1:tf); We use the formulations for the x and y series Think of the “.” % now let's calculate the x and y series x=v0*cos(alfa*pi/180)*t; y=v0*sin(alfa*pi/180)*t-.5*g*(t).^2; ENG004.01

  11. The Code of the Flight Problem Let’s estimate the max values from the x and y series. In order to create the x and y series, we need to create the time series: % min and max commands xmax2=max(x); ymax2=max(y); % let's see the results in the command window fprintf('The highest altitude of the flight is %.2f m \n',ymax2) fprintf('The distance of the landing point is %.2f m \n',xmax2) ENG004.01

  12. The Code of the Flight Problem Let’s run the program and see the results! clc,clear,close all v0=input('Please enter the initial velocity : ') alfa=input('Pleae enter the horizontal angle : ') g=input('Please enter the gravitaty acceleration : ') % The following line calculates the duration of the fligth tf=2*v0*sin(alfa*pi/180)/g; % max distance xmax=v0*cos(alfa*pi/180)*tf; % ymax ymax=v0*sin(alfa*pi/180)*tf/2-.5*g*(tf/2)^2; % let's see the results in the command window fprintf('The highest altitude of the flight is %.2f m \n',ymax) fprintf('The distance of the landing point is %.2f m \n',xmax) % time series t=(0:.1:tf); % now let's calculate the x and y series x=v0*cos(alfa*pi/180)*t; y=v0*sin(alfa*pi/180)*t-.5*g*(t).^2; % min and max commands xmax2=max(x); ymax2=max(y); fprintf('The highest altitude of the flight is %.2f m (by using alternative way)\n',ymax2) fprintf('The distance of the landing point is %.2f m (by using alternative way)\n',xmax2) ENG004.01

  13. Assignment 3 Let’s create a vector matrix (x) and perform the following formulation. f(x)=variable1*x^3+variable2*x^2-2*x And estimate the min and max values. ENG004.01

  14. Send your diary files to class e-mail ENG004.01

  15. Next week... ENG004.01

  16. See you next week! ENG004.01

More Related