Write a MATLAB function file which accepts an inputs of x an


Write a MATLAB function file which accepts an inputs of x and returns a value of z based on the following mathematical description: z = {x - 1 if x

Solution

%% MATLAB code to find Z based on X value;

clear
clc
x = input(\'Enter X = \ \');
if (x<0)
z = x-1;
elseif (x==0)
z = x+3;
elseif (x>0&&x<1)
z = 5*x+2;
elseif(x>1)
z=1000*x;
end
sprintf(\'z =%d \ \',z)

%% output:

Enter X =
-5

ans =

z =-6

%% Output :

Enter X =
0

ans =

z =3

%% Output :

Enter X =
0.3

ans =

z =3.500000e+000

%% Output :

Enter X =
2

ans =

z =2000

 Write a MATLAB function file which accepts an inputs of x and returns a value of z based on the following mathematical description: z = {x - 1 if x Solution%%

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site