You are on page 1of 30

Page 1 of 30

6.8 PROBLEMS:

TCH=[75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 82
84 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 68
68 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 in
Chicago.\n',sum(TCH>mean(TCH)))
fprintf('%g days temperature is above the average in
San fransisco.\n',sum(TSF>mean(TSF)))
%c;
Page 2 of 30

fprintf('%g days temp in San Fransisco was lower than


Chicago,on the following days of the
month:\n',sum(TSF<TCH))
disp(find(TSF<TCH))
%d;
fprintf('%g days temp in was the same on both cities,on
the following days of the month:\n',sum(TSF==TCH))
disp(find(TSF==TCH))

p=input('please enter the number to see the fibonacce


numbers until it');
a=0; b=1;c=[0 1];
for i=2:inf
c(i+1)=c(i)+c(i-1);
if c(i)+c(i+1)>p
break
end
end
disp(c)

Page 3 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(i1)*factorial(j-1));
end
end
disp(p)
for i=1:1:7
for j=1:1:7

Page 4 of 30

p(i,j)=factorial(i+j-2)/(factorial(i1)*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 1st
two element; ');
for i=1:1:n
for j=1:1:n
if i==1
d(j+2)=d(j)+d(j+1);
c(i,j)=d(j);
Page 5 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
Page 6 of 30

disp(c)
disp(det(c))

a=input('enter the value of a ;');


b=input('enter the value of b ;');
c=input('enter the value of c ;');
D=b^2-(4*a*c);
if D>0
fprintf('the equation has two roots.\n %i & %i
\n',(-b+D)/2,(-b-D)/2)
else if D==0
fprintf('the
\n',-b/2)

equation has only one root.\n %i

Page 7 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

Page 8 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)

Page 9 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
end
P
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

Page 10 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)))

Page 11 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');

Page 12 of 30

INTEN=input('please enter your fitness (low,medium or


high): ','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
Page 13 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;
Page 14 of 30

if BMI<18.5
fprintf('Your BMI value is %g,which classifies you
as Underweight. \n',BMI)
else if BMI>=18.5 & BMI<=24.9
fprintf('Your BMI value is %g,which classifies
you as Normal. \n',BMI)
else if BMI>=25 & BMI<=29.9
fprintf('Your BMI value is %g,which
classifies you as Overweight.\n',BMI)
else
fprintf('Your BMI value is %g,which
classifies you as Obese',BMI)
end
end
end

Page 15 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<10
s=0.1*dur
end
Page 16 of 30

if dur>=10&dur<=30
s=1+(0.08*(dur-10))
end
if dur>30
s=2.60+(0.06*(dur-30))
end
case'evening'
if dur>=1&dur<10
s=0.07*dur
end
if dur>=10&dur<=30
s=0.7+(0.05*(dur-10))
end
if dur>30
s=1.70+(0.04*(dur-30))
end
case'night'
if dur>=1&dur<10
s=0.04*dur
end
if dur>=10&dur<=30
s=0.4+(0.03*(dur-10))
end
Page 17 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<p
disp('error..your payment is not sufficient!!')
else
ch=payment-p;
fprintf('your change is $%i \n',ch)
end
Page 18 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')

Page 19 of 30

p=input('please enter your number: ')


x=p;
for i=1:inf
x(i+1)=(x(i)+(p/x(i)))/2;
E=abs((x(i+1)-x(i))/x(i));
if E<0.000001
break;
end
end
disp(x(i))

Page 20 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
end
if k<=2
m=m+1;
x(m)=n;
end
end
for c=1:(length(x)-1)
if (x(c+1)-x(c))==2
l=l+1;
z(l)=x(c);
Page 21 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 be
converted): ','s');
switch inunit
case 'm3'
outm3=inp;
outL=inp*37.854118;
outft3=inp/30.48;
case 'L'
outL=inp;
outm3=inp/37.854118;
Page 22 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)<=B
Page 23 of 30

j=j+1;
x(j)=x(j-1)+s;
end
end
disp(mean(x))

t=input('Enter no. of iterations: ');


x=0; y=0;
for n=1:t
x(n+1)=0.5*x(n)+0.25;
y(n+1)=0.5*y(n)+sqrt(3)/4;

end
plot(x,y)

Page 24 of 30

table=reshape(randperm(12),6,2);
disp('League table')
disp(' ')
disp(table)

Page 25 of 30

gas=input('please enter one of the next gases to find


it''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 another
extra 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'
Page 26 of 30

Cp=48.5+9.188*10^-2*T-8.54*10^-5*T.^2+32.4*10^9*T.^3;
case 'O2'
Cp=29.1+1.158*10^-2*T-0.6076*10^5*T.^2+1.311*10^-9*T.^3;
case 'N2'
Cp=29+0.2199*10^-2*T-0.5723*10^-5*T.^22.871*10^-9*T.^3;
otherwise
disp ('error')
end
dis(1,:)=T; dis(2,:)=Cp;
disp(gas)
disp('

temp.

Heat_capacity ')

disp(dis')

Page 27 of 30

Page 28 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: ');
Page 29 of 30

Rp=input('Enter your Rounds played\n')


if Rp>=5&Rp<=6
N=1
end
if Rp>=7&Rp<=8

N=2
end
HCD=(score-CR)./CS*113;
t=[HCD N]

Page 30 of 30

You might also like