Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

Week 3 Lecture

Uploaded by

yz7cqfknbf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Week 3 Lecture

Uploaded by

yz7cqfknbf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

a=7

a = 7

E=3

E = 3

d=[5 a+E 4 E^2]

d = 1×4
5 10 4 9

g=[a a^2 13;a*E 1 a^E]

g = 2×3
7 49 13
21 1 343

whos

Name Size Bytes Class Attributes

E 1x1 8 double
a 1x1 8 double
d 1x4 32 double
g 2x3 48 double

input function
midterm1=75

midterm1 = 75

midterm2=93

midterm2 = 93

final=68

final = 68

avg_points=(midterm1+midterm2+final)/3

avg_points = 78.6667

table(midterm1,midterm2, final)

ans = 1x3 table


midterm1 midterm2 final

1 75 93 68

clear;clc;

1
student1=input('what is your name','s') % characters data type
% 's' means string type data
m1=input('please enter your score') % enter numbers by default

student2=input('what is your name','s') % characters data type


% 's' means string type data
m2=input('please enter your score') % enter numbers by default

student3=input('what is your name','s') % characters data type


% 's' means string type data
m3=input('please enter your score') % enter numbers by default

fprintf('Student Name: %s. Score:%i', student1, m1)


fprintf('Student Name: %s. Score:%i', student2, m2)
fprintf('Student Name: %s. Score:%i', student3, m3)

Chapter 5 Plotting
clear;clc;clf
x=1:5:10
y=10:10:100
hold on
plot(x,y,'o')

plot(x,y, '--g')

hold off
plot(x,y,'^r')

plot of given data


year=[1988:1994]
sales=[8 12 20 22 18 24 27]
plot(year, sales, 'o',year,sales, '--r')

function plot
f='x^2+4*sin(2*x)-1'
fplot(f)
fplot(f,[-3 3])

Curve Fitting App


year=[1988;1994]
sales=[8 12 20 22 18 24 27]

2
plot(year, sales, 'o')

createFit(year, sales)

plotting with subplots


x=1:25

y=sin(x).*cos(x)

y2=tan(x)
y3=csc(x).*tan(x)
%creating 3x1 plots
subplot(3,1,1)

plot(x,y)
subplot(3,1,2)
plot(x,y2)
subplot(3,1,3)
plot(x,y3)

3x2 subplots symbolic


clear;clc;clf

syms x

y=cos(x)*sin(x)
dy=diff(y)
d2y=diff(y,2)
d3y=diff(y,3)
d4y=diff(y,4)
d5y=diff(y,5)

subplot(3,2,1)
fplot(y)
subplot(3,2,2)
fplot(dy)
subplot(3,2,3)
fplot(d2y)
subplot(3,2,4)
fplot(d3y)
subplot(3,2,5)
fplot(d4y)
subplot(3,2,6)
fplot(d5y)

random graphs

3
clear;clc;clf

syms x

y=cos(x)*sin(x)
dy=diff(y)
d2y=diff(y,2)
d3y=diff(y,3)
d4y=diff(y,4)
d5y=diff(y,5)

subplot(3,3,1)
fplot(y)
subplot(3,3,2)
fplot(dy)
subplot(3,3,3)
fplot(d2y)
subplot(3,3,[4 7])
fplot(d3y)
subplot(3,3,5)
fplot(d4y)
subplot(3,3,[5 6 8 9])
fplot(d5y)

Other graphs
clear;clc;clf
yr=[1988:1994]
sle=[8 12 20 22 18 24 27]

bar(yr, sle) % vertical bar plot


barh(yr,sle,'r')
xlabel('year')

ylabel('sle')
stairs(yr,sle)

stem(yr,sle)

Grade=[11 18 26 9 5]
pie3(Grade)

histogram

y=[58 73 73 53 50 48 56 73 73 66 69 63 74 82 84 91 93 89 91 80 59 69 56 64
63 66 64 74 63 69 ]

4
hist(y)
hist(y,3)
xlabel('T')
ylabel('Frequency')

x=45:10:95
hist(y,x)

t=linspace(0,2*pi,200)

r=3*cos(0.5*t).^2+t
polar(t,r)

Chapter 4 In Class Exercise Problem 3


clear;clc;
r= 8
h=22

r=input('Enter cone radius r=')


h=input('Enter cone height h=')
a=h*r
b=r+sqrt(h^2+r^2)
r=a/b

Chapter 5 In Class Exercise Problem 3


clear;clc;
f='3*cos(1.7*x)*exp(1)^(-0.3*x)+(2*sin(1.4*x)*exp(1)^(0.3*x))'
syms 'x'
fplot(f,[-7,7])

Chapter 4 Homework
problem 11

clear;clc;

h: -500:500:10000

Unrecognized function or variable 'h'.

p=29.921*(1-6.8753e-6*h)
Tb=49.16*log(p)+44.932
tbl=[h' Tb']
disp(' Boling')
disp(' Altitude Temperature')
disp(' (ft) (degF)')

5
disp(tbl)

Problem 23
clear;clc;
m=1:7

m = 1×7
1 2 3 4 5 6 7

a=[cosd(28.5) 1 0 0 0 0 0
sind(28.5) 0 0 0 0 0 0
-cosd(28.5) 0 -cosd(58.4) 0 cosd(58.4) cosd(28.5) 0
-sind(28.5) 0 -sind(58.4) 0 -sind(58.4) -sind(28.5) 0
0 0 0 -1 -cosd(58.4) 0 1
0 0 0 0 0 sind(28.5) 0
0 0 0 0 0 -cosd(28.5) -1]

a = 7×7
0.87882 1 0 0 0 0
0.47716 0 0 0 0 0
-0.87882 0 -0.52399 0 0.52399 0.87882
-0.47716 0 -0.85173 0 -0.85173 -0.47716
0 0 0 -1 -0.52399 0
0 0 0 0 0 0.47716
0 0 0 0 0 -0.87882

b=[3000; -6521; -3000; 0; 0; -7479; 0]

b = 7×1
3000
-6521
-3000
0
0
-7479
0

x=a\b

x = 7×1
-13666
15010
9397.6
10086
7039.6
-15674
13775

tbl=[m' x]

tbl = 7×2
1 -13666
2 15010
3 9397.6
4 10086
5 7039.6
6 -15674
7 13775

6
disp(' Member Force (lb)')

Member Force (lb)

disp(tbl)

1 -13666
2 15010
3 9397.6
4 10086
5 7039.6
6 -15674
7 13775

Problem 27
clear;clc;
A=[1 2 1 1
2 3 0 1
1 4 1 0
1 3 2 0]

A = 4×4
1 2 1 1
2 3 0 1
1 4 1 0
1 3 2 0

B=[5; 12; 11; 8]

B = 4×1
5
12
11
8

Points=A\B

Points = 4×1
4
2
-1
-2

Chapter 5 Homework
Problem 15

clear;clc;
x=linspace(-1,1,200)

x = 1×200
-1 -0.98995 -0.9799 -0.96985 -0.9598 -0.94975

y1=x1.^(2/3)+sqrt(1-x1.^2)

7
Unrecognized function or variable 'x1'.

y2=x1.^(2/3)-sqrt(1-x1.^2)
x1=[0:0.01:1]
x2=[0:-0.01:-1]
plot(x1, y1, x1, y2, x2, -y1, x2,-y2)
plot(x1, y1, x1, y2, x2, y1, x2,y2)

Problem 25
clear;clc;
th=70

th =
70

v0=200

v0 =
200

g=9.81

g =
9.81

syms t
solve((g*t^2)/2 == v0*t*sin(th))

ans =

t=linspace(0, 31.5552, 200)

t = 1×200
0 0.15857 0.31714 0.47571 0.63428 0.79284

ht=v0*t*sin(th)-(g*t.^2)/2

ht = 1×200
0 24.42 48.593 72.519 96.199 119.63

vt=sqrt(v0^2-2*v0*g*t*sin(th)+g^2*t.^2)

vt = 1×200
200 198.8 197.6 196.41 195.22 194.04

subplot(2,1,1)
plot(t,ht)
xlabel('Time')
ylabel('Height')
subplot(2,1,2)

8
plot(t,vt)
xlabel('Time')
ylabel('Velocity')

Problem 37

You might also like