Upload
osman-tolhildan
View
230
Download
0
Embed Size (px)
Citation preview
8/13/2019 Solution Chapter (6) MATLAP
1/30
Page 1 of 30
8/13/2019 Solution Chapter (6) MATLAP
2/30
Page 2 of 30
6.8 PROBLEMS:
TCH=[75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 8284 81 79 73 69 73 79 82 72 66 71 69 66 66];
TSF=[69 68 70 73 72 71 69 76 85 87 74 84 76 68 79 75 6868 73 72 79 68 68 69 71 70 89 95 90 66 69];
%a;
fprintf('average temp for the month in Chicago is;%g\naverage temp for the month in San fransisco is;%g\n',mean(TCH),mean(TSF))
%b;
fprintf('%g days temperature is above the average inChicago.\n',sum(TCH>mean(TCH)))
fprintf('%g days temperature is above the average inSan fransisco.\n',sum(TSF>mean(TSF)))
%c;
8/13/2019 Solution Chapter (6) MATLAP
3/30
Page 3 of 30
fprintf('%g days temp in San Fransisco was lower thanChicago,on the following days of the
month:\n',sum(TSF
8/13/2019 Solution Chapter (6) MATLAP
4/30
Page 4 of 30
for a=1:1:4
for b=1:1:3
c(a,b)=(a+b)/b^2;
end
end
disp(c)
for i=1:1:4
for j=1:1:4
p(i,j)=factorial(i+j-2)/(factorial(i-1)*factorial(j-1));
end
enddisp(p)
for i=1:1:7
for j=1:1:7
8/13/2019 Solution Chapter (6) MATLAP
5/30
Page 5 of 30
p(i,j)=factorial(i+j-2)/(factorial(i-1)*factorial(j-1));
end
end
disp(p)
n=input('please enter anumber to cnstruct n*n matrix;');
d=input('please enter two different values for the 1sttwo element; ');
for i=1:1:n
for j=1:1:nif i==1
d(j+2)=d(j)+d(j+1);
c(i,j)=d(j);
8/13/2019 Solution Chapter (6) MATLAP
6/30
Page 6 of 30
else if i==2
d(j+n)=d(j+n-1)+d(j+n-2);
c(i,j)=d(j+n);
else if i==3
d(j+2*n)=d(j+(2*n-1))+d(j+(2*n-2));
c(i,j)=d(j+2*n);
else if i==4
d(j+3*n)=d(j+(3*n-1))+d(j+(3*n-2));
c(i,j)=d(j+3*n);else if i==5
d(j+4*n)=d(j+(4*n-1))+d(j+(4*n-2));
c(i,j)=d(j+4*n);
else if i==6
d(j+5*n)=d(j+(5*n-1))+d(j+(5*n-2));
c(i,j)=d(j+5*n);
end
end
end
end
end
end
end
end
8/13/2019 Solution Chapter (6) MATLAP
7/30
8/13/2019 Solution Chapter (6) MATLAP
8/30
Page 8 of 30
else
fprintf('the equation has no real root.\n')
end
end
n=1;
while true
if (rem(n,11)==0 & sqrt(n)>132)
fprintf('The required number is: %i\n',n);
break
else
n=n+1;
end
end
format long
8/13/2019 Solution Chapter (6) MATLAP
9/30
Page 9 of 30
m=input('please enter the m value :');
for n=0:1:m
x=(-1/3)^n/(2*n+1);
end
y=sqrt(12)*x;
disp(y)
format long
c=1;
m=input('please enter avalue: ');
for n=1:m
c=c*(2*n)^2/((2*n)^2-1);
end
disp(2*c)
8/13/2019 Solution Chapter (6) MATLAP
10/30
Page 10 of 30
format short
x=[-3.5 -5 6.2 11 0 8.1 -9 0 3 -1 3 2.5];
for n=1:length(x)
if x(n)>=0
P(n)=x(n);
else
N(n)=x(n);
end
endP
N
x=[-3.5 5 -6.2 11.1 0 7 -9.5 2 15 -1 3 2.5];
for i=1:1:length(x)
for j=i+1:1:length(x)
if x(i)>x(j)
k=x(i);x(i)=x(j);
x(j)=k;
else continue
8/13/2019 Solution Chapter (6) MATLAP
11/30
Page 11 of 30
end
end
end
disp(x)
scores=input('please enter 20 exam scores as an arrey.: ');
s=sort(scores)
fprintf('the average of the eight top scores is: %g\n',mean(s(13:20)))
8/13/2019 Solution Chapter (6) MATLAP
12/30
Page 12 of 30
format long
x=input('please enter the value of angle in degrees:');
y=pi/180*x;
E=1; n=0; S=0;
while E>0.000001
S(n+2)=((-1)^n/factorial(2*n+1)*y^(2*n+1));
E=abs((S(n+2)-S(n+1))/S(n+1))
n=n+1;
end
fprintf('sine(%g) = %g\n',x,sum(S))
gender=input('please enter your gender: ','s');
8/13/2019 Solution Chapter (6) MATLAP
13/30
Page 13 of 30
INTEN=input('please enter your fitness (low,medium orhigh): ','s');
age=input('please enter your age: ');
RHR=input('please enter your resting heart rate: ');
while strcmp(INTEN,'low')==1
if strcmp(gender,'male')
THR1=(220-age-RHR)*0.55+RHR
else
THR2=(206-0.88*age-RHR)*0.55+RHR
end
INTEN=0;
end
while strcmp(INTEN,'medium')==1
if strcmp(gender,'male')
THR3=(220-age-RHR)*0.65+RHR
else
THR4=(206-0.88*age-RHR)*0.65+RHR
end
INTEN=0;
end while strcmp(INTEN,'high')==1
if strcmp(gender,'male')
THR5=(220-age-RHR)*0.8+RHR
8/13/2019 Solution Chapter (6) MATLAP
14/30
Page 14 of 30
else
THR6=(206-0.88*age-RHR)*0.8+RHR
end
INTEN=1;
End
W=input('please enter your weight in lb: ');
H=input('please enter your height in inches: ');
BMI=703*W/H^2;
8/13/2019 Solution Chapter (6) MATLAP
15/30
Page 15 of 30
if BMI=18.5 & BMI=25 & BMI
8/13/2019 Solution Chapter (6) MATLAP
16/30
Page 16 of 30
format bank
time=input('please enter the time when the call made in(day,evening or night) : ','s');
duration=input('please enter the duration of the call :');
dur=ceil(duration);
switch time
case 'day'
if dur>=1 & dur
8/13/2019 Solution Chapter (6) MATLAP
17/30
Page 17 of 30
if dur>=10&dur30
s=2.60+(0.06*(dur-30))
end
case'evening'
if dur>=1&dur=10&dur30
s=1.70+(0.04*(dur-30))
end
case'night'
if dur>=1&dur=10&dur
8/13/2019 Solution Chapter (6) MATLAP
18/30
Page 18 of 30
if dur>30
s=1+(0.02*(dur-30))
end
end
format bank
p=randi(20);
fprintf('the amount to be paid is..: $%i \n',p),
payment=input('Enter the vale of your payment:$');
if payment
8/13/2019 Solution Chapter (6) MATLAP
19/30
Page 19 of 30
%a;
Dg=150; Vd=50; Ka=1.6; Ke=0.4;
t=0:10;cp=Dg*Ka./(Vd*(Ka-Ke)).*(exp(-Ke*t)-exp(-Ka*t))
plot(cp,t,'r--*','markeredgecolor','b')
%b;
t=0:4:24
Cp=Dg*Ka./(Vd*(Ka-Ke))*(exp(-Ke*t)-exp(-Ka*t))
figure
plot(Cp,t,'--k')
8/13/2019 Solution Chapter (6) MATLAP
20/30
Page 20 of 30
p=input('please enter your number: ')
x=p;
for i=1:infx(i+1)=(x(i)+(p/x(i)))/2;
E=abs((x(i+1)-x(i))/x(i));
if E
8/13/2019 Solution Chapter (6) MATLAP
21/30
Page 21 of 30
m=0; l=0;
for i=10:500
k=0;
for j=1:i
if rem(i,j)==0
k=k+1;
n=i;
else continue
end
endif k
8/13/2019 Solution Chapter (6) MATLAP
22/30
Page 22 of 30
z(l+1)=x(c+1);
l=l+1;
end
end
v=reshape(z,2,22)'
inp=input('Enter an amount of volume: ');
inunit=input('Its current unit: ','s');
out=input('Enter the your desired new units(to beconverted): ','s');
switch inunit
case 'm3'
outm3=inp;
outL=inp*37.854118;
outft3=inp/30.48;
case 'L'
outL=inp;
outm3=inp/37.854118;
8/13/2019 Solution Chapter (6) MATLAP
23/30
Page 23 of 30
outft3=inp*35.287;
case 'ft3'
outft3=inp;
outm3=inp*0.0283;
outL=outm3/30;
end
switch out
case 'm3'
disp(outm3)case 'L'
disp(outL)
case 'ft3'
disp(outft3)
end
B=10; x(1)=0; j=1; s=abs(randn(1,1));
for i=1:100
while x(j)
8/13/2019 Solution Chapter (6) MATLAP
24/30
8/13/2019 Solution Chapter (6) MATLAP
25/30
Page 25 of 30
table=reshape(randperm(12),6,2);
disp('League table')
disp(' ')
disp(table)
8/13/2019 Solution Chapter (6) MATLAP
26/30
Page 26 of 30
gas=input('please enter one of the next gases to findit''s heat capacity (SO2,SO3,O2,N2)','s');
T=input('please enter the current temperature: ');
i=1;
while true
temp=input('is the calculation needed for anotherextra temperature? enter(yes or no)','s');
i=i+1;
if strcmp(temp,'no')==1
break
else if strcmp(temp,'yes')==1
T(i)=input('please enter the extra temperature:');
end
end
end
switch gas
case 'SO2'
Cp=38.91+3.904*10^-2*T-3.105*10^-5*T.^2+8.606*10^-9*T.^3;
case 'SO3'
8/13/2019 Solution Chapter (6) MATLAP
27/30
8/13/2019 Solution Chapter (6) MATLAP
28/30
Page 28 of 30
8/13/2019 Solution Chapter (6) MATLAP
29/30
Page 29 of 30
score=input('please enter your score as vector: ');
CR=input('please enter your course reting as vector:');
CS=input('please enter your score as vector: ');
8/13/2019 Solution Chapter (6) MATLAP
30/30
Rp=input('Enter your Rounds played\n')
if Rp>=5&Rp=7&Rp