Final Review 2024

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 16

Final Review

Intro to computer for engineering


Topics
– Basic commands in Matlab
– Mathematical operations with matrixes and vectors
– Solve system of equations
– Plots and graphs (chapter 2,4,5)
– Script and function files (chapter 3)
– Logical Operators and Conditional Statements (chapter 3,4)
– Iteration: For and While command (chapter 4)
– Flowchart (chapter 4)
– Curve fitting (chapter 2,4)
– Logistic Equation
– Symbolic solver:
• Ordinary Differential Equation (ODE)
• Integration Equation
Basic Matlab
Coulomb’s Law:

q1q2
F  kc 2
Newtons
r
1
kc 
4 o
 o  8.854 x10 12 Fm 1
The charge of an electron is: q = 1.602 x 10-19 coulombs.
Matrixes
1. Write a Matlab function file that generates a (NxN) matrix A:

A should have the following properties: All odd rows should alternate between 5, Row#, 5,… while all
even rows should alternate between 1,Row#,1,Row#,…

5 1 5 1 .. 5
1 2 1 2 .. 1 The inputs to the function should be the integer N and the output should be the matrix A.
5 3 5 3 .. 5 function A=problem1(N)
A
1 4 1 4 .. 1
A(N,N)=5;
.. .. .. .. .. ..
A(2:2:N,:)=1;
1 N 1 N .. 1
for row=1:N

for col=1:2:N

A(row,col)=row;

end

end
Matrixes Operation

Write a matlab command to perform the followings:

 Create the matrix A


 Calculate the determinant of the matrix A
 Calculate the invert matrix A-1
 Calculate the covariance matrix of A
System of Equations
• Solve the following system of equations:

-2x+y=3
x+y=10
Joe and Steve are saving money. Joe
starts with $105 and saves $5 per week.
5x+3y-z=10
Steve starts with $5 and saves $15 per
3x+2y+z=4 week. After how many weeks do they have
4x-y+3z=12 the same amount of money?

3x+y+z+w=24
x-3y+7z+w=12
2x+2y-3z+4w=17
x+y+z+w=0
Plot and graph
1. Write a matlab script file that computes and plots 5 cycles of a sine wave as a function of
time?

a. Assume the sine wave has a frequency f = 100 Hz or period (cycle) T=1/f = 0.01s

b. An amplitude of A=2.0

c. A phase angle phi=180 degrees = 1pi

The equation of the sine wave is given by:

y(t) = A sin(2*pi*f*t+phi)
Basic Matlab and Plot
Consider the following normal (Gaussian) distribution
function:

Write a Matlab script file to plot f(x) for x = -1 to x=1 (with


resolution of at least 1000 points) where =0, and 2=1 (or
standard normal distribution function)
Function and script file:

• Should be able to write function and script file


• Know how to write equations:
• Y(x)=Sin(x)+25x, x=0-100
• Know how to plot, label, title, axis setting
• IF, while, for loop
Write a following functions
Convert degree to radian.
Convert Celsius to Fahrenheit.
(F=1.8C + 32)
Logical Operators and Conditional
Statements

• We want to calculate
with a conditional
statement if:

• Ask the user to input x,


• Perform the
calculation as provided
Iteration: For and While
• We want to calculate with
a conditional statement if:

• Using Loop to perform the


calculation for x=-5 to 30
• Plot the x versus y from
x=-5 to 30
Flowchart Start
Input
ABC

Compute the
perimeter p

Compute the Area


A

Displa
yp
and A

Start
Curve Fitting
• Should be able to use polyfit and polyval commands

Vietnam Population
• 2012 91.993 • 2000 77.635 • 1990 66.017
• This is the data for
• 2011 90.763 • 1999 76.597 • 1989 64.774
the Vietnamese • • •
2010 88.257 1998 75.456 1988 63.5
population (in • 2009 87.211 • 1997 74.307 • 1987 62.3
millions) from 1980 • 2008 86.177 • 1996 73.157 • 1986 60.92
to 2012. Select the • 2007 85.155 • 1995 71.996 • 1985 59.71
best curve for this • 2006 84.156 • 1994 70.825 • 1984 58.57
data and predict the • 2005 83.106 • 1993 69.645 • 1983 57.47
population of 2025. • 2004 82.032 • 1992 68.45 • 1982 56.4
• 2003 80.899 • 1991 67.242 • 1981 55.31
• 2002 79.727 • 1980 54.18
• 2001 78.686
Logistic Equation

• A contagious disease is spreading in a town of dy  y 


M=10,000 people. There were 200 infected  ky1  
people when the outbreak was discovered y(0), dt  M
and the number grew up to 1,000 after one y (0)  200
month y(1). Assuming the logistic model for the
spread of the disease is: y (1)  1000

• Find the number of infected people three


months after the outbreak y(3) ? M
y (t ) 
• Plot the number of infected people for 6  M 
months. 1    1e  kt
 y (0) 
Symbolic: integration

2
• Use syms to solve :  sin( x)dx
4
Symbolic: ODE
• Use syms to solve :
e  3e  54
2x x

dy
 7y x2 3

dx
y ( 2)  3

You might also like