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

Consider the function, f(x,y) = (x-a)^-1 +(y-b)^x * sqrt(xy) (Matlab programming

ID: 3553385 • Letter: C

Question

Consider the function, f(x,y) = (x-a)^-1 +(y-b)^x * sqrt(xy) (Matlab programming)


(a) Write MATLAB which takes values for x and y from the user and evaluates the

expression. The user should be able to either real or complex values, so the function

must be defined correctly for complex numbers (for full marks this should be able to deal with vector inputs). Errors should be thrown cases which are undefined. Submit

your code in a Separate *.m file.


(b)Write a second version in which inputs and outputs are restricted the real number

line. Errors should be thrown if the user tries to enter complex values. Submit your

code in a Separate *.m file.


Explanation / Answer

The first part......


clc;


promptx = 'Enter "x" complex/real number(in a+bi format): ';


x = input(promptx);


prompty = 'Enter "y" complex/real number(in a+bi format): ';


y = input(prompty);


prompta = 'Enter "a": ';


a = input(prompta);


promptb = 'Enter "b": ';


b = input(promptb);


f = 1/(x-a) +(y-b)^x * sqrt(x*y) ;


f







The second part can be done.....


clc;


errorstring = 'x and y should be real';

promptx = 'Enter "x" complex/real number(in a+bi format): ';


x = input(promptx);


if(imag(x) ~= 0)

errordlg(errorstring);

clc;


else

prompty = 'Enter "y" complex/real number(in a+bi format): ';

y = input(prompty);


if(imag(y) ~= 0)

errordlg(errorstring);

clc;


else

prompta = 'Enter "a": ';

a = input(prompta);


promptb = 'Enter "b": ';

b = input(promptb);


f = 1/(x-a) +(y-b)^x * sqrt(x*y) ;


f

end

end