MATLAB QUES A mathematical relationship between x and y is described by the foll
ID: 3763198 • Letter: M
Question
MATLAB QUES
A mathematical relationship between x and y is described by the following expressions:
y=A*exp(x^2)-B*x^3+x-1 y=A*log10(x)-B*x^4+1.5 y=A/log(x)-B/x+C
if x<=0 (Case 1)
if 0<x<=10 (Case 2) if x>10 (Case 3)
where A, B, and C are constants. Write a program that inputs the constants A,B,C, and the argument x, and computes the corresponding value of y. Print x by using 4 decimal places, and y by using 5 decimal places.
Use if/else statements to choose the proper expression for y, corresponding to selected x.
After reading A,B,C, your program should use a while loop to evaluate y for scanned x in each of the above three cases. If you input x from the same interval again, your program should ask you to input x from another interval, until you input x once from each interval.
Your output should look like:
Enter A, B, C: -1.5 2.5 0.125
Enter x:
-3.5
Case 1
x value is = -3.5000 and y value is = -313369.24580
Enter x:
-5
Enter x from another interval!
Enter x:
1.85
Case 2
x value is = 1.8500 and y value is = -28.18452
Enter x:
12
Case 3
x value is = 12.0000 and y value is = -0.68698
Explanation / Answer
clc;
clear all;
input1=1;
flag_c1=0;
flag_c2=0;
flag_c3=0;
round=1;
A=input('Enter Value A');
B=input('Enter Value B');
C=input('Enter Value C');
while(input1==1)
% A=-1.5;
% B=2.5;
% C=0.125;
x=input('Enter x: ');
if (x<=0 && flag_c1<round)
disp('Case 1');
y=A*exp(x^2)-B*x^3+x-1;
flag_c1=flag_c1+1;
fprintf('x value is = %.5f and y value is = %.5f ',x,y);
elseif (x>0 && x<=10 && flag_c2<round)
disp('Case 2');
y=A*log10(x)-B*x^4+1.5;
flag_c2=flag_c2+1;
fprintf('x value is = %.5f and y value is = %.5f ',x,y);
elseif(x>10 && flag_c3<round)
disp('Case 3');
y=A/log(x)-B/x+C;
flag_c3=flag_c3+1;
fprintf('x value is = %.5f and y value is = %.5f ',x,y);
else
fprintf('Enter x from another interval! ');
end
if(flag_c1==round && flag_c2==round && flag_c3==round)
round=round+1;
end
end
------------------------------------------------------------------------------------------------------------------------
Enter Value A: -1.5
Enter Value B: 2.5
Enter Value C: 0.125
Enter x: -3.5
Case 1
x value is = -3.50000 and y value is = -313369.24580
Enter x: -5
Enter x from another interval!
Enter x: 1.85
Case 2
x value is = 1.85000 and y value is = -28.18452
Enter x: 12
Case 3
x value is = 12.00000 and y value is = -0.68698
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.