Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using Matlab , show step using if, elseif , else statements. Problem A2: The rel

ID: 2084300 • Letter: U

Question


using Matlab , show step using if, elseif , else statements.

Problem A2: The relationship between the input x and output y of a system is given as: 0, if Ixls at y x a, if x a a, if x -a where a is positive scalar parameter. Write a MATLAB script that simulates the response of the system for a given positive scalar a and an input x specified by the user. If the user enters a negative value for a, then your script must use the absolute value of the parameter and display a warning message to the user.

Explanation / Answer

x1='enter lower limit of x ';
x2='enter upper limit of x';
input(x1,'s');
input(x2,'s');
x=linspace(x1,x2);
a='enter value of a';
input(a)
if(a<0)
warning('Plesae enter positive values only');
abs(a);
end

if(x<=a)
y=0;
elseif(x>a)
y=x-a;
elseif(x<-a)
y=x+a;
end

display(y);