Y Sin (Pi X) Fprintf ( /N y %F /N, Y)
Y Sin (Pi X) Fprintf ( /N y %F /N, Y)
0 )
y = sin ( pi * x );
fprintf ( \n y = %f \n, y );
else
y = 3.0;
fprintf (\n constant level \n );
end
syms x;
for n=[2:7]
disp(['I will take the derivative of ',char(x^n)])
disp(['The derivative of ',char(x^n),' is ',char(diff(char(x^n),'x'))])
end
total = 0;
n=0;
while(total<1000)
n = n+1;
total = total + n;
end
disp(n)
x = ones(1,10);
for n = 2:6
end
For example, find the first integer n for which factorial(n) is a 100-digit number:
n = 1;
nFactorial = 1;
n = n + 1;
nFactorial = nFactorial * n;
end
1. Make sure your if statements do not include redundant tests. This makes your code
more difficult to understand, harder to maintain over time, and slower to execute. The
following is an example of a poorly-designed if statement with 4 unnecessary redundant
tests.
if Score >= 90
disp('A')
elseif Score >= 80 & Score < 90
disp('B')
elseif Score >= 70 & Score < 80
disp('C')
elseif Score >= 60 & Score < 70
disp('D')
elseif Score < 60
disp('F')
end
if Score >= 90
disp('A')
elseif Score >= 80
disp('B')
elseif Score >= 70
disp('C')
elseif Score >= 60
disp('D')
else
disp('F')
end