Vous êtes sur la page 1sur 25

Sana Zahid

Problem 1
A particular circular cylindrical tank is 15 m tall and has a radius 8 m. We want to construct another cylindrical tank with a volume 20 % greater but having the same height. How large must its radius be?

Solution
r=8;
h=15; V= pi*r^2*h;

V=V+0.2*V or V=1.2*V;
r=sqrt(V/(pi*h))

Managing Working Session

Polynomial Roots
x3 - 7x2 + 40x 34 = 0 MATLAB commands; >>a= [1,-7,40,-34]; >>roots(a) ans = 3.0000 + 5.000i 3.0000 - 5.000i 1.0000

Saving Data
clear D = 2; v = 3; rho = 1000; mu = 0.001; NRe = D*v*rho/mu; f = 0.076*NRe^(-0.25); save data1 D v rho mu NRe f

Loading Data
clear load data1 who Your variables are:

D NRe
D D= 2

rho mu v

Common Mathematical Functions


exp (x) sqrt (x) log (x) log10 (x) cos (x) sin (x) tan (x) acos (x) asin (x) atan (x)

Problem:
Determine how many elements are in the array

cos(0):0.02: log10(100). Determine the 25th element. Find the roots of the polynomial 290-11x+6x2+ x3

Plotting With MATLAB


plot (x,y) grid gtext( temperature ) title( graph between temp, press & vol) xlabel( pressure ) ylabel( volume ) Plot (x,y, + )

Problem:
Plot the function s=2 sin(3t+2)+(5t+1) over the

interval 0<=t<=5. put a title on the plot and properly label the axes. The variable s represents speed in feet per second; the variable t represents time in seconds

Linear Algebraic equations


6x + 12y +4z = 70 7x 2y +3z = 5 2x +8y 9z = 64 >>A = [6,12,4;7,-2,3;2,8,-9]; >>B = [70;5;64]; >>Solution = A\B Solution = 3 5 -2

Problem:
Use the Matlab to solve the following set of equations. 6x-4y+8z= 112 -5x+7z-3y=75 14x+9y-5z=-67

Script file and Editor/Debugger


Two ways to operate with MATLAB; 1. Interactive mode (for small calculations) 2. Script File (for complex or big problems)
MATLAB programs are saved in .m format. M-files are built with the Editor/Debugger.

M-files
1.

2.

Script files; contains a sequence of MATLAB commands, and is useful when you need to use many commands or arrays with many elements. Function files; useful when you need to repeat the operation of a set of commands. You can create your own function files. (Detail in Chapter 3)

How to run script file? Use of Comments?

>> % Mass Transfer Program MATLAB ignores every thing to the right of the % symbol

Example of Script File


% Program example.m % This program computes the sine of % the square root and displays the results. x = sqrt ([5:2:30]); y = sin (x); z = cos (x); plot(x,y,x,z)

Debugging
Debugging; process of finding and removing the

bugs or errors in a program. Syntax Error; related to typing or grammatical mistake, MATLAB detects it automatically. Runtime error; are due to incorrect formula or input. We have to find and fix it. e.g. Division by Zero.

Programming Style
1. 2. 3. 4.

Comment Section Input Section Calculations Section Output Section

See Example of a good script file in your book at Page 37

For Changing MATLAB Look

Input/Output commands
disp (A) disp ( Text ) x = input ( text )

num2str command
% This m-file calculates the area of a circle, % and displays the result. radius = 2.5; area = pi * 2.5 ^ 2; disp (area)

Assignment
Problems: Section 1.1( 1 to 6 group 1) Section 1.1 (6 to 12 group 2) Section 1.3 (13 to 18 group 3) Section 1.3 (19 to 24 group 4)

Practice more and more & Have a nice dash.


(b +ve)

Vous aimerez peut-être aussi