2
2
% function next_hr=nexthour(current_hour)
% if current_hour==12
% next_hr=1
% else
% next_hr=current_hour+1
% end
% end
% next_hr=nexthour(current_hour)
% %7
% if employment_2016>employment_2017
% else
% end
% %8
% if a<=0||c<=0 || c<=a
% fprintf('error')
% end
% function b = findb(a,c)
% b = sqrt(c^2 - a^2);
% end
% b = findb(a,c)
% %13
% if A1==A2
% elseif A1>A2
% else
% end
%Chap5
%%6
% function loop=sumsteps(n)
% loop=0
% for i=1:2:n
% loop=loop+i
% end
% end
% loop=sumsteps(11)
%8
% number=randi([2,5])
% total=0
% for i=1:number
% total=total+user_input
% end
% %15
% for i=1:5
% for j=1:i
% fprintf('%6d',i*j)
% end
% fprintf('\n')
% end
% %21
% myprod = 1;
% i = 1;
% i = i + 1;
% end
%23
% n=1;
% exp=0.36787;
% approximation= (1-(1/n))^n;
% value= exp-approximation;
% while abs(value)>=0.0001
% n=n+1
% approximation= (1-(1/n))^n;
% end
% %27
% function prtemps()
% fprintf('error')
% end
% fprintf('%6s,%6s\n','F','C')
% for F=0:5:1000
% C=(5/9)*(F-32)
% if C>max_celsius
% fprintf('error')
% break
% end
% fprintf('%6.1f,%6.1f\n',F,C)
% end
% %28
% while true
% user_input=input('>','s');
% if user_input==('q')
% break
% end
% end
% %#23
% n=1
% exp=0.3679
% approximation= (1-(1/n))^n
% value=exp-approximation
% while abs(exp-approximation)>=0.0001
% n=n+1
% approximation= (1-(1/n))^n
% end
%28
% while true
% n=input('>','s')
% if strcmp(n,'q')
% break
% end
% fprintf('You entered:%s\n',n)
% end
%Chap6
% %4
% function [positive,negative]=splitm(vec)
% positive=vec(vec>=0)
% negative=vec(vec<0)
% end
% vec=[-10,5,8,-4,7,-9]
% [positive,negative]=splitm(vec)
% disp(negativenumbers)
% %14
% figure(1)
% x=1:10:60
% y=1:10:60
% plot(x,y,'r*:')
% xlabel('time')
% ylabel('time2')
% mat = [4 2 4 3 2; 1 3 1 0 5; 2 4 4 0 2];
% [r, c] = size(mat);
% totalSum=0
% for i = 1:r
% totalSum=sumprint(mat(i,:),totalSum);
% end
% rowSum = sum(row);
% end
% %2
% function [miles,naustical]=convertkilometer(k)
% miles=k*0.621;
% naustical=k/1.852;
% end
% K = input('Enter a value of k:'); % Distance in kilometers
% %4
% function [positivenumbers,negativenumbers]=splitem(vec)
% positivenumbers= vec(vec>=0)
% negativenumbers=vec(vec<0)
% end
% vec=[-10,-3,5,4,9,-7];
% [positivenumbers,negativenumbers]=splitem(vec);
% disp(positivenumbers)
% disp(negativenumbers)
% %14
% function inches=cubit2inch(cubit)
% inches=cubit*18
% end
% inches=cubit2inch(cubit)
% %17
function [r,theta,phi]=convert2spher(x,y,z)
r=sqrt(x^2+y^2+z^2);
if r==0
theta=0;
else
theta=acos(z/r);
end
phi=0;
else
phi=atan(y/x);
end
end
function printspherical(x, y, z)
end
x=5;y=6;z=8;
printspherical(x, y, z)
midterm
% A=25/5-2;
% B=10-2^3;
% C=[5 -1 0];
% D=[2 6 3.5];
% E=C*D';
% disp('Hello World!')
% else
% switch user_number
% case 1
% Rec_perimeter=R_perimeter(user_number,B)
% case 2
% case 3
% user_number=user_number+3^3
% otherwise
% G=ones(B,A)^2
% end
% end
% function perimeter=R_perimeter(a,b)
% perimeter=(a+b)*2;
% end
%5
% for j = 1:cols
% if matrix(i, j) >= 0
% else
% end
% end
% end
% return;
% end