How can I solve this problem using if-else statement?
17 views (last 30 days)
Consider the following continuous mathematical function y =f(x):
y = 1 for x < -1
y = x^2 for -1 <= x <= 2
y = 4 for x > 2
Using if-else statement, write a script named findY.m that promotes the user for a value for x and returns a value for y using the function y = f(x).
Kumar Pallav on 21 Mar 2022
You can solve the problem by using the conditional statements (if/else).Please refer this link for more on if/elseif/else staements.
To take user input, use the input command.
You can create scripts in MATLAB which are the simplest codes having no input or output arguments. Refer to this to learn more on writing scripts in MATLAB with examples.
Hope it helps! Happy learning!