Thursday, December 10, 2015

MatLAB home Work 12

Contents

PROBLEM 1

clear,clc

syms x X
ex1 = x^2-1;
EX1 = sym('X^2-1');
eq1 = sym('x^2 = 1');
EQ1 = sym('X^2 = 1');

one = subs(ex1,x,4)
two = subs(EX1,X,4)
three = subs(eq1,x,4)
four = subs(EQ1,X,4)

% one = 15
% two = 15
% three = 16==1
% four = 16==1
 
one =
 
15
 
 
two =
 
15
 
 
three =
 
16 == 1
 
 
four =
 
16 == 1
 

PROBLEM 2

V = 0:2:10;

V1 = subs(ex1,x,V)
V2 = subs(EX1,X,V)
V3 = subs(eq1,x,V)
V4 = subs(EQ1,X,V)

% This works for the V1 and V2, which have whole intergers place inside
% their vecotrs. For V3 and V4, each vector component is an equality of two
% numbers that don't make any sense.
 
V1 =
 
[ -1, 3, 15, 35, 63, 99]
 
 
V2 =
 
[ -1, 3, 15, 35, 63, 99]
 
 
V3 =
 
[ 0 == 1, 4 == 1, 16 == 1, 36 == 1, 64 == 1, 100 == 1]
 
 
V4 =
 
[ 0 == 1, 4 == 1, 16 == 1, 36 == 1, 64 == 1, 100 == 1]
 

PROBLEM 3

clear,clc

syms a b c A B C x X
ex4 = a*x^2 + b*x + c;
EX4 = sym('A*X^2 + B*X +C');
eq4 = sym('a*x^2 + b*x + c = 0');
EQ4 = sym('A*X^2 + B*X + C = 0');

x_ex = subs(ex4,{a b c x},{3 4 5 [0:0.5:5]})
X_EX = subs(EX4,{A B C X},{3 4 5 [0:0.5:5]})
x_eq = subs(eq4,{a b c x},{3 4 5 [0:0.5:5]})
X_EQ = subs(EQ4,{A B C X},{3 4 5 [0:0.5:5]})

% all results are symbolic
 
x_ex =
 
[ 5, 31/4, 12, 71/4, 25, 135/4, 44, 223/4, 69, 335/4, 100]
 
 
X_EX =
 
[ 5, 31/4, 12, 71/4, 25, 135/4, 44, 223/4, 69, 335/4, 100]
 
 
x_eq =
 
[ 5 == 0, 31/4 == 0, 12 == 0, 71/4 == 0, 25 == 0, 135/4 == 0, 44 == 0, 223/4 == 0, 69 == 0, 335/4 == 0, 100 == 0]
 
 
X_EQ =
 
[ 5 == 0, 31/4 == 0, 12 == 0, 71/4 == 0, 25 == 0, 135/4 == 0, 44 == 0, 223/4 == 0, 69 == 0, 335/4 == 0, 100 == 0]
 

PROBLEM 4

clear,clc

syms f m g L I

Y = sym('((2*pi)*f = sqrt((m*g*L)/I))')

L = solve(Y,L)
 
Y =
 
2*pi*f == (-L*g*m*1i)^(1/2)
 
 
L =
 
(pi^2*f^2*4i)/(g*m)
 

PROBLEM 5

clear,clc

syms mt mb x

water = sym('50 = 0.2*mt + 0.65*mb');
ethanol = sym('0 = -100*x + 0.35*mt + 0.25*mb');
methanol = sym('50 = 100*x + 0.45*mt + 0.1*mb');

[x,mass_top,mass_bottom] = solve([water,ethanol,methanol],[x,mt,mb])
 
x =
 
0.28333333333333333333333333333333
 
 
mass_top =
 
33.333333333333333333333333333333
 
 
mass_bottom =
 
66.666666666666666666666666666667
 

No comments:

Post a Comment