Anda di halaman 1dari 7

Chapter-1: Starting with MATLAB

Question no. 16

=
=
sin () sin () sin ()

Answer:
a=9 ; b=18; c=25;
%Question (a): Rearrange the cosine equation
alpha = acosd((a^2-b^2-c^2)/(-2*b*c))
%Question (b): the value shall be 0_deg<beta<90_deg and 90_deg<gamma<180_deg
beta = asind(b*sind(alpha)/a)
gamma = 180-asind(c*sind(alpha)/a)
%Question (c): just sum the value of alpha, beta, and gamma
check = alpha+beta+gamma
Chapter-1: Starting with MATLAB
Question no. 26

Answer:
n=52; r=5;
Cnr=factorial(n)/(factorial(r)*factorial(n-r))

Chapter-2: Creating Arrays


Question no. 16 (It is different from our books, but the methodology still same)

Answer:
A=[linspace(0,30,7);linspace(600,0,7);linspace(0,5,7)]
Chapter-2: Creating Arrays
Question no. 30

Answer:
B=[linspace(18,13,6);linspace(12,7,6);linspace(6,1,6)]
% Question (a)
va=[B(:,2);B(:,5)]
% Question (b)
vb=[B(3,3:6)';B(:,2)]
% Question (c)
vc=[B(:,2);B(:,4);B(:,6)]
Chapter-2: Creating Arrays
Question no. 39

Answer:
a=[eye(2),zeros(2,1),ones(2)]
b=[zeros(2),ones(2);zeros(1,4);ones(1,4)]
c=[ones(1,2),zeros(1,2),ones(1,1);ones(3,2),zeros(3,3)]

Chapter-3: Mathematical Operation With Array


Question no. 4

Answer:
t=[0:1:8]' % it's optional to use transpose (') option
y=((20*t.^(2/3))./(t+1))-(((t+1).^2)./exp(0.3*t+5))+(2./(t+1))
Chapter-3: Mathematical Operation With Array
Question no. 15 (It is different from our books, but the methodology still same)

Answer:
p=2.3;w=5.67;
t=[1,2,3,4,5];x=[2.8,2.5,2.2,1.9,1.6];y=[4,7,10,13,17];
% Question (a)
T=p*((x+y).^2).*w./y
% Question (b)
S=p*(x+y).^2/(y*w)+w*x.*t./(p*y)
Chapter-3: Mathematical Operation With Array
Question no. 31 (It is different from our books, but the methodology still same)

Answer:
% Define the coefficient of x,y,z respectively
% A1 is coefficient in equation 1
A1=[3 -2 5];A2=[-4.5 2 3];A3=[5 1 -2.5];
% b1 is a function result
b1=7.5;b2=5.5;b3=4.5;
% Put all linear equation into one form of Matrix, so it will become
% [A]*[c]=[b]
% [c]=inv([A])*[b]
xyz=inv([A1;A2;A3])*([b1;b2;b3])

Chapter-4: Mathematical Operation With Array


Question no. 19

Answer:
% Create temperature ranging between 200 to 400 deg Celcius with
% 20 deg increment
T=[200:20:400]';
% Assumed that coeffient value is store in *.xls file
c=xlsread('coefficient.xls','coefficient','B2:E5');
% After read it, you will find it in 4x4 matrix form
% Used it in the main equation. You can use UDF if you want :)
TSO2=c(1,1)+c(1,2)*T+c(1,3)*(T.^2)+c(1,4)*(T.^3)
TSO3=c(2,1)+c(2,2)*T+c(2,3)*(T.^2)+c(2,4)*(T.^3)
TO2 =c(3,1)+c(3,2)*T+c(3,3)*(T.^2)+c(3,4)*(T.^3)
TN2 =c(4,1)+c(4,2)*T+c(4,3)*(T.^2)+c(4,4)*(T.^3)
% Assumed that we want the result is presented in *.txt file
fid=fopen('heat_capacity.txt','w')
fprintf(fid,'Heat Capacity for Each Gas \n')
fprintf(fid,'Temp. \t SO2 \t SO3 \t O2 \t O3 \n')
fprintf(fid,'%5.0f %5.2f %5.2f %5.2f %5.2f\n',T,TSO2,TSO3,TO2,TN2)
fclose(fid)

Chapter-5: Two-Dimensional Plots


Question no. 31

It should be L

Answer:
% constant value
L=20; E=200E9; I=348E-6; w=5.4E3; M=200E3;
% Define x domain. Remember that there are 2 equations, so we need to
% define x1 and x2 for each equation
x1=[0:0.01*L:0.5*L]
x2=[0.5*L:0.01*L:L]
% Write the equations
y1=(-w*x1/(384*E*I)).*(16*x1.^3-24*L*x1.^2+9*L^3)+(M*x1/(6*E*I*L)).*(x1.^23*L*x1+2*L^2);
y2=(-w*L/(384*E*I)).*(8*x2.^3-24*L*x2.^2+17*x2*L^2L^3)+(M*x2/(6*E*I*L)).*(x2.^2-3*L*x2+2*L^2);
% Plot the data.
x=[x1 x2]';
y=[y1 y2]';
plot(x,y,'LineStyle','-','color','k');
title('Deflection of The Beam in x-y Coordinate','FontSize',12)
xlabel('x(m)');ylabel('y(m)');
Deflection of The Beam in x-y Coordinate

-3

x 10

y(m)

-5

-10

10
x(m)

12

14

16

18

20

Chapter-7: User-Defined Functions and Function Files


Question no. 22

Solution:
http://www.mathopenref.com/coordgeneralellipse.html

function ellipseplot(xc,yc,a,b)
% Since the root of the quadratic have 2 values (+ & -), then the equation
%
shall be rearrange into two equation. Otherwise, it only generate a
%
half ellipse
x1=linspace(xc-a,xc+a,100);
x2=x1
y1= sqrt(b^2*(1-(((x1-xc).^2)./a^2)))+yc;
y2=-sqrt(b^2*(1-(((x2-xc).^2)./a^2)))+yc;
plot(x1,y1,'b',x2,y2,'b')
xlabel('x')
ylabel('y')
end
% This is the script/input file. Please run this file!
% Question (a)
xc_1=3.5 ;yc_1=2.0 ;a_1=8.5 ; b_1=3;
figure(1)
ellipseplot(xc_1,yc_1,a_1,b_1)
% Question (b)
xc_2=-5 ;yc_2=1.5 ;a_2=4
; b_2=8;
figure(2)
ellipseplot(xc_2,yc_2,a_2,b_2)

Chapter-7: User-Defined Functions and Function Files


Question no. 29

Solution:
% Actually this question can be solved using User-Defined Function. But,
%
Anonymous Funtions is can be used as an alternative.
Smax=@ (Sxx,Syy,Sxy) ((Sxx+Syy)/2)+sqrt(((Sxx-Syy)/2)^2+Sxy^2)
Smin=@ (Sxx,Syy,Sxy) ((Sxx+Syy)/2)-sqrt(((Sxx-Syy)/2)^2+Sxy^2)
% Question (a)
S1=[Smax(-190,145,110) Smin(-190,145,110)] % in MPa
% Question (b)
S2=[Smax(14,-15,8) Smin(14,-15,8)]
% in ksi