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

Write a script that satisfies these criteria: Prompt the user for the minimum x

ID: 2080030 • Letter: W

Question

Write a script that satisfies these criteria: Prompt the user for the minimum x value, maximum x value, and the number of points to use. Check that maximum x value is larger than minimum x. If it is not then prompt user to enter the values again. Do this until he/she gets it right. Create a vector of x values using the range of values entered by the user. Invoke the math fun function and pass the x vector to it. On a linear-linear graph, make a plot of y versus r. Use an appropriate graph title and axes labels. Write a function named math fun that accepts a vector of x values as the input argument and returns a vector of y values as the output argument. Within the function, each element of y is calculated according to the following mathematical equation y = {x^2 if x

Explanation / Answer

MAIN PROGRAM

close all;
clc;
Min_X=input('Enter minimum value of X ');
Max_X=input('Enter maximum value of X ');
while(Max_X<=Min_X)
disp('error: Max_X is less than Min_X ');
disp('enter again');
Min_X=input('Enter minimum value of X ');
Max_X=input('Enter maximum value of X ');
end
N=input('Enter number of points between Min_Xand Max_X');
X=linspace(Min_X,Max_X,N);
Y=mathfun(X,N);
plot(X,Y);

FUNCTION

function Y=mathfun(X,N)
for i=1:N
if X(i)<0
Y(i)=X(i)*X(i);
end
if X(i)>=0
Y(i)=sqrt(X(i));
end
end

end

SAVE FUNCTION as separate matlab file and main program as separate and both programs should be in same folder.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote