Download presentation
Presentation is loading. Please wait.
Published byCarmella Cobb Modified over 8 years ago
1
MATHLAB Prepared for: Md. Monzur Ashraf Prepared By: Md. Shafiul Parvez Aakaash
2
Prepared by: Md. Shafiul Parvez Aakaash BEGIN Let, a=4, b= -3 A=6 Variable names in MATHLAB represent matrix quantities. A row vector can be assigned as follows: a=[1 2 3 4 5] A column vector can be entered as follows: b=[ 1; 2; 3; 4; 5] Or by transforming a row vector with ` operator b=[ 1 2 3 4 5]`
3
Prepared by: Md. Shafiul Parvez Aakaash 2 Dimensional Matrix Representations A=[1 2 3;4 5 6;7 8 9] Or A=[1 2 3; 4 5 6; 7 8 9] A [press Enter] Who [Press Enter] Whose [Press Enter]
4
Prepared by: Md. Shafiul Parvez Aakaash Complex Variable i=sqrt(-1) X= 2+ i*4 ^ means exponent ional Y=pi/4 Y^2.45
5
Prepared by: Md. Shafiul Parvez Aakaash Graph Plotting To create a graph of t,y arrays command should be Plot (t, y) For Title: Title(‘ U ’r Text’) For X Label: Xlabel (‘ U ’r Text’) For Y Label: Ylabel (‘ U ’r Text’) Grid Example: X=[0:2:100] Y= sinX Plot (X,Y)
6
Prepared by: Md. Shafiul Parvez Aakaash Polynomials C=[ 1 1 1 1 ] & then r=roots (c) Now roots of x 3 +x 2 +x+1=0 will be stored in r array.
7
Prepared by: Md. Shafiul Parvez Aakaash Solution Of Linear Equation A=[ 1 1 -1;2 3 5;3 2 -3] B=[2; -3 ; 6] X=inv (A)*B Or, X=A\B [It will apply Gauss Elimination internally] N.B: inv (A) makes inverse of matrix A
8
Prepared by: Md. Shafiul Parvez Aakaash Make Polynomial From Roots Procedure 1: >>A=[ 2,3] Ploy (A) 2. Evaluate Polynomial: >>Y=polyval (p,x) p is a vector of polynomial. x is a vector of X 3. Fit Polynomial To Data: >>Polyfit (X,Y,N) >>X= [0 1 2 4] >>Y= [1 1 2 5] Polyfit (X, Y, 3) Combine 2 & 3: Fn= polyfit (X,Y,3) Val= polyval ( fn, 4)
9
Prepared by: Md. Shafiul Parvez Aakaash Interpolation Let, X=[1 3 4 6] Y=[4 7 8 11] P=spline (X, Y, 2) 2 is the value of X Answer: 5.8000
10
Prepared by: Md. Shafiul Parvez Aakaash Differentiation & Integration Question: f (x)=. 2+25x-200x 2 +675x 3 - 900x 4 +400x 5. From a=0 to b=.8 Answer: Write in Mfile function y= fx(X) y=.2+25*x-200*x.^2+675*x.^3- 900*x.^4+400*x.^5; Now, Save as fx.m >>q=quad (‘fx’, 0,.8) N.B: fx is the function name used in Mfile
11
Prepared by: Md. Shafiul Parvez Aakaash Tabular Data LET, >>X=[0.12.22.32.36.4.44.54.64.7.8] >>Y=fx (X) N.B: For different value of X value of Y will be different >>integral=trapz (X, Y) >>diff (X) Summary in the next slide……….
12
Prepared by: Md. Shafiul Parvez Aakaash Summary Of Previous Method Result represents the difference between each pair of elements of x. To compute divided difference approximations of the derivative, we merely perform a vector division of the Y differences by the X differences by entering >>D= diff (Y)/ diff (X)
13
Prepared by: Md. Shafiul Parvez Aakaash Curve Fitting Technique In MATHLAB >>X=0:10 >>Y=sin (X) >>plot (X, Y) But If We Do So, >>P= polyfit ( X, Y, 5) >>X2=0:.25:10 >>Y2= polyval (P, X2) >>plot (X2, Y2) N.B: We will get a smooth curve except previous one.
14
Prepared by: Md. Shafiul Parvez Aakaash Circuit Solution Using MATHLAB LET, asin t= L di / dt + q / C +Ri So, di/dt=1/L(asin t- q/C – Ri) Let here, di=x (1) Here, 20 a=30 R=230 L=200 C=200 = 1 / 200 [ 30*sin (20*t) - q / 200 - 230*i] Dq/dt =i Let here, dq=x (2) Solution in the net slide……………………..
15
Prepared by: Md. Shafiul Parvez Aakaash Solution Of Previous Question In Mfile: function yp=circuit (t,x) yp= [(1/200)*(30*sin (20*t) – (x(2)/200) – (230*x(1)));x(1)]; In command Line: >>I=[0, 0] >>[t,x]=ode45 (‘circuit’,[0:01:10],ic); >>plot (t, x) N.B: ‘circuit’ is the name of Mfile that you are saved in this name. Hints: This Method is as like as Predator Pray method
16
Prepared by: Md. Shafiul Parvez Aakaash Numeric Solution Of ODE Question: dx/dt=.1x – y; dy/dy= x + 01*y; dz/dt= sin[(x2+y2)*t] Draw curve & find values of x, y, z W.R.T t ?
17
Prepared by: Md. Shafiul Parvez Aakaash Symbolic Expression #Symbolic expression never handle with the value of a variable. Example: >>syms X >>diff (X^3) #Output will be 3*X^2 #If you previously define >>X=3 After the symbolic expression (syms) Mathlab never handle with the value of X.
18
Prepared by: Md. Shafiul Parvez Aakaash Variable Precision Arithmetic Example: >> vpa 19/81 70 #Means, compute 19/81 up to 70 digits. OR, >>A=vpa(’80!’,200) #Means, Compute 80 factorial with 200 digits arithmetic.
19
Prepared by: Md. Shafiul Parvez Aakaash Length Of A Character See the previous example. f is a variable, contain the factorial of 80. Now I wanna know what is the total length of f. Put this command on Mathlab command prompt. >>length (char (f))
20
Prepared by: Md. Shafiul Parvez Aakaash Example Question: Employ the trapezoidal rule to evaluate the vertical distance by a rocket, if the vertical velocity is given by, V=10t 2 -5t 0<= t <=10 V=1000-5t 10<= t <=20 V=45t+2(t-20) 2 20<= t <=30 Hints: Solve in the next slide
21
Prepared by: Md. Shafiul Parvez Aakaash Solve Of Previous Question >>t=[0:29] >>V (1:10) =10*square (t(1:10))-5*t(1:10) >>V(11:20)=1000–5*t(11:20) >>V(21:30)=45*t(21:30)+2*square (t(21:30- 20) >>plot (t, V) >>trapz (t, V)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.