In: Computer Science
Create a MATLAB code that does the following
Given the vector y=[0,-0.2,0.4,-0.6,0.8,-1.0,-1.2,-1.4,1.6]. If z=sin(y), then:
Determine the minimum and maximum of only the negative values of z and then determine the square root of only the positive values of z.
clc;clear all
y=[0 -0.2 0.4 -0.6 0.8 -1 -1.2 -1.4 1.6]; %Given vector y
z=sin(y);j=1;k=1; %Calculate z= sin(y)
for(i=1:length(z)) %RUnning a loop till length of z
if(z(i)>=0) %If element is positive finds its root and stores it
in sqroot
sqroot(j)=sqrt(z(i));
j=j+1;
end
if(z(i)<0) %If element is negative copies it to a new vector
newv
newv(k)=z(i);
k=k+1;
end
end
posroot=sqroot %Prints the root of all positive value
maxinz=max(newv) %Prints maximum of all negative value
mininz=min(newv) %Prints minimum of all negative value