Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENG004 ALGORITHMS & INT. TO PROGRAMMING Week 4 “Arrays and Matrix Operations III” Ahmet Anıl Dindar 21.03.2007.

Similar presentations


Presentation on theme: "ENG004 ALGORITHMS & INT. TO PROGRAMMING Week 4 “Arrays and Matrix Operations III” Ahmet Anıl Dindar 21.03.2007."— Presentation transcript:

1 ENG004 ALGORITHMS & INT. TO PROGRAMMING Week 4 “Arrays and Matrix Operations III” Ahmet Anıl Dindar 21.03.2007

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

3 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”

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

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

6 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.(t flight ) 2- The highest altitude of the fligth. (ymax) 3- The distance between the origin and landing point. (xmax)

7 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 (V 0 ) 2- The horizontal angle (  ) 3- The gravity acceleration (g) Then the code should calculate 1- The duration of the object’s fligth.(T flight ) 2- The highest altitude of the fligth. (y max ) 3- The distance between the origin and landing point. (x max )

8 ENG004.01 8 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 user input lines The computer calculations % The following line calculates the duration of the fligth tflight=2*v0*sin(alfa*pi/180)/g ;

9 ENG004.01 9 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 computer should calculate the x max and y max. 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)

10 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 % 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; Think of the “.”

11 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)

12 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)

13 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.

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

15 ENG004.01 15 Next week... WeeksDateClassAssignment 121.02Introduction to the classRegistration 228.02Exploring MATLABAssignment 1 307.03 Arrays and Matrix Operations N.A. 414.03 Arrays and Matrix Operations Assignment 2 521.03 Arrays and Matrix OperationsAssignment 3 628.03Polynomials and curve-fitting Assignment 4 704.04Descriptive statistics Assignment 5 811.04Programming Elements of MATLAB N.A. 918.04Programming Elements of MATLAB Assignment 6 1025.04Programming Elements of MATLAB Assignment 7 1102.05Plotting and Animations N.A. 1209.05Plotting and Animations Assignment 8 1316.05Numerical Integration Assignment 9 1423.05Symbolic Math Assignment 10 1530.05Take-home final projectN.A.

16 ENG004.01 16 See you next week!


Download ppt "ENG004 ALGORITHMS & INT. TO PROGRAMMING Week 4 “Arrays and Matrix Operations III” Ahmet Anıl Dindar 21.03.2007."

Similar presentations


Ads by Google