(1) Write a MATLAB function named q13 that reads two inputs x and y and returns
ID: 2292523 • Letter: #
Question
(1) Write a MATLAB function named q13 that reads two inputs x and y and returns one output z. All x, y, and z can be scalar or vector. Write a condition that if length of x and length of y are not equal then it writes "Error, choose x and y of the same size", otherwise it define z equals e to the power of x cos left parenthesis y right parenthesis. Use this example: x [1 2] and y [3 4] (2) Write a MATLAB script file that subtracts all the even numbers between 2 and 45 (2 not included) except 30 from 700, and displays the answer. Note you should not subtract 30 and add it again.Explanation / Answer
1)
x=[1 2];
y=[3 4];
xlen=length(x);
ylen=length(y);
if xlen~=ylen
disp('Error,choose x and y of the same size');
else
z=x.^cos(y);
end
disp(z);
command window output:
problem 2:
val=700;
for k=2+1:45
if mod(k,2)==0 && k~=30
val= val-k;
end
end
disp(val);
output:
226
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.