Matlab, Chap#6, Exercise
Matlab, Chap#6, Exercise
Matlab, Chap#6, Exercise
6
Problems
Q#1
function[cm,kg]=STtoSI(in,lb)
cm=in*2.54;
kg=lb*0.4535;
(a)
>> [cm,kg]=STtoSI(70,175)
cm =
177.8000
kg =
79.3625
(b)
>> [cm,kg]=STtoSI(72.5,138)
cm =
184.1500
kg =
62.5830
Q#2
function y = Poly(x)
y = 0.9 * x.^4 - 12 * x.^2 - 5 * x;
(a)
>> y=Poly(-3)
y=
-20.1000
>> y=Poly(5)
y=
237.5000
(b)
>> x=[-4:4];
>> y=Poly(x);
>> plot(x,y)
Q#3
function[r]=polar(th)
r = 2*(1.1-sin(th).^2);
(a)
>> [r]=polar(pi/3), [r]=polar(3*pi/2)
r=
0.7000
r=
0.2000
(b)
>> th=[0:2*pi];
>> [r]=polar(th);
>> polarplot(th,r)
Q#4
function[x, y]= maxmin(a, b, c)
x = -b / (2 * a);
y=(a*x^2+b*x+c);
(a)
>> a=input ('Enter value of a:');
[x,y]=maxmin(a,b,c)
x=
y=
21
Q#5
function [P] = saval (po, r,t)
P=po*(1+r/100)^t;
>> P=saval(10000,0.06,13)
P=
1.0078e+04
Q#6
function Nm=lbintoNm(lbin)
Nm=lbin/8.8507;
>> Nm=lbintoNm(500)
Nm =
56.4927
Q#7
function [alpha, beta, gamma] = triangle(a, b, c)
if a + b <= c || a + c <= b || b + c <= a
error('Invalid side lengths. Cannot form a triangle.');
end
alpha = acosd((b^2 + c^2 - a^2) / (2 * b * c));
beta = acosd((a^2 + c^2 - b^2) / (2 * a * c));
gamma = acosd((a^2 + b^2 - c^2) / (2 * a * b));
(a)
>> a=input ('Enter length of 1st side:');
alpha =
34.0477
beta =
122.8783
gamma =
23.0739
Q#8
function n = unitvec(A, B)
AB =B-A;
magnitude = norm(AB);
n = AB / magnitude;
(a)
>> A=[2,6,5]; B=[-10,15,9];
>> n=unitvec(A,B)
n=
d=
5.9537
Q#10
(a)
function[g]=fgrade(a1,a2,a3,a4,a5,m1,m2,f1)
g=0.2.*(a1+a2+a3+a4+a5)+0.2.*m1+0.2.*m2+0.4.*f1;
g=
67.8000
(b)
%Script File
StudentA=fgrade(7, 9, 5, 8, 10, 90, 70, 85);
StudentB=fgrade(6, 4, 7, 0, 7, 60, 71, 50);
StudentC=fgrade(5, 9, 10, 3, 5, 45, 75, 80);
StudentD=fgrade(8, 8, 7, 7, 9, 82, 81, 88);
>> Studentgrades_script
>> StudentA
StudentA =
73.8000
>> StudentB
StudentB =
51
>> StudentC
StudentC =
62.4000
>> StudentD
StudentD =
75.6000
Q#11
function REQ = req (R)
REQ =
15.1771
Q#12
function n = radint(a,b)
n = (b-a)*rand+a;
>> n=radint(1,49)
n=
31.3532
Q#13
function I= Ibeam(w, h, t)
>> I= Ibeam(w, h, t)
I=
4.4656e+08
Q#14
function[smax,smin]=princstress(sxx,syy,sxy)
smax=(sxx+syy)/2+sqrt(((sxx-syy)/2)^2+sxy^2);
smin=(sxx+syy)/2-sqrt(((sxx-syy)/2)^2+sxy^2);
>> [smax,smin]=princstress(150,-40,80)
smax =
179.1974
smin =
-69.1974
>> [smax,smin]=princstress(-12,-16,-7)
smax =
-6.7199
smin =
-21.2801
Q#15
function RV = RV_lowpass(R, C, w)
RV = 1 ./ sqrt(1 + (w * R * C).^2);
% lowpass_plot_script.m
R = input('Enter the value of R (ohms): ');
C = input('Enter the value of C (Farads): ');
w_values = logspace(-2, 6, 1000); % Frequency values from 10^-2 to
10^6 rad/s
RV_values = RV_lowpass(R, C, w_values);
>>%Command Window
>> lowpass_plot_script
Q#16
function RV=bandpass(R,C,L,w)
Z1 = w .* R .* C;
Z2 = (1 - (w.^2) .* L .* C);
RV = Z1 ./ sqrt(Z2.^2 + Z1.^2);
>> bandpass_script