Question

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

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.

Solutions

Expert Solution

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


Related Solutions

Solve the Following Equation: y'' + y' + y = a*sin(ω*t), y(0) = 0 , y'(0)...
Solve the Following Equation: y'' + y' + y = a*sin(ω*t), y(0) = 0 , y'(0) = 0 Thanks
Solve the following system : w ′ + y = sin x y ′ − z...
Solve the following system : w ′ + y = sin x y ′ − z = ex z ′ + w + y = 1; w(0) = 0, y(0) = 1, z(0) = 1
Matlab Code that does the following: Takes as input 3 frequencies. Create a signal that is...
Matlab Code that does the following: Takes as input 3 frequencies. Create a signal that is a mixture of the 3 signals. Create a bandpass filter that only selects the center frequency. Output the filtered signal which contains only the middle frequency. Plot in time and frequency domain the original signal and the filtered signal. Show the output for filter order 1 and 15. Upload a pdf of the image files. Each figure should have your name in the title...
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a sinusoid wave having two components as f1 = 3kHz and f2 = 5kHz and then sample it with fs = 10kHz. Calculate its fft with zero frequency component in the middle. Plot it on a properly scaled w-axis. Specify if there is aliasing or not? If there is aliasing specify which component is casing the aliasing
Write your own MATLAB code to solve the system 10 − x + sin(x + y)...
Write your own MATLAB code to solve the system 10 − x + sin(x + y) − 1 = 0 8y − cos2 (z − y) − 1 = 0 12z + sin(z) − 1 = 0 using a residual tolerance of 10^−6 and the initial guess, ~x 0 = [0.1, 0.25, 0.08]^T . Print out the values for x, y and z for each iteration in a table similar to the one you created for the problems of the...
Q1. Interpolationv (MATLAB PROGRAM ) : Suppose that x = 0:10;? y = [1.5, 1.0, 0.9,...
Q1. Interpolationv (MATLAB PROGRAM ) : Suppose that x = 0:10;? y = [1.5, 1.0, 0.9, 2.6, 2.2, 0.03];? a)Use both linear interpolation and cubic spline interpolation function to determine the value of y when x= 3.5 b) Plot both functions y and the interpolated version of y. PLEASE SOLVE THE QUESTION USING MATLAB PROGRAM .
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications: Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4. The plot should have: (1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin...
Using Matlab code, solve the following: (a) Consider first the undamped pendulum ? + sin ?...
Using Matlab code, solve the following: (a) Consider first the undamped pendulum ? + sin ? = 0, ?(0) = 0, ? (0) = b. Let x = ? and y = ? ; then x and y satisfy the system x = y y = ? sin x, x(0) = 0 y(0) = b. Solve this system numerically and plot, on a single graph, the resulting trajectories for the initial velocities b = 0.5, 1, 1.5, 2, 2.5. Use...
The vector field given by E (x,y,z) = (yz – 2x) x + xz y +...
The vector field given by E (x,y,z) = (yz – 2x) x + xz y + xy z may represent an electrostatic field? Why? If so, finding the potential F a from which E may be obtained.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT