How can I type this in MATLAB Evaluate the function y 2x3

How can I type this in MATLAB

Evaluate the function y = (2x^3 - 16x + 41)^2/x + 50. Create an x vector, x = -2.0, -1.2, -0.4, 0.4, 1.2, 2.0, 2.8, and 3.6 using automatic vector spacing, then calculate the \"y\" vector by using a \"for\" loop.

Solution

x= -2:0.8:3.6;%defining the vector x using automatic spacing
[r c]=size(x);%finding the size of x, c gives no. of columns in the vector
y=zeros;
for i=1:c%running the for loop for c times
y(i)=(((2*x(i)^3)-(16*x(i))+41)^2)/(x(i)+50);%finding the y value for each element in vector x
end
disp(y);%displaying the y vector

Output:

x= -2:0.8:3.6;%defining the vector x using automatic spacing
[r c]=size(x);%finding the size of x, c gives no. of columns in the vector
y=zeros;
for i=1:c%running the for loop for c times
y(i)=(((2*x(i)^3)-(16*x(i))+41)^2)/(x(i)+50);%finding the y value for each element in vector x
end
disp(y);%displaying the y vector

Output:

Columns 1 through 3

67.6875 65.9812 45.0533

Columns 4 through 6

23.9292 12.4583 12.0192

Columns 7 through 8

30.4608 109.7898

How can I type this in MATLAB Evaluate the function y = (2x^3 - 16x + 41)^2/x + 50. Create an x vector, x = -2.0, -1.2, -0.4, 0.4, 1.2, 2.0, 2.8, and 3.6 using

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site