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

Part 2: solve the question using matlab program: Use if …. elseif … else … struc

ID: 2292988 • Letter: P

Question

Part 2: solve the question using matlab program:

Use if …. elseif … else … structure to solve the following problems:

Copy the following header and put it at the top of your script                                 (5 points)

%%%%%%% Copy this code exactly as it is ... do not modify it

%Final Examination…. PART #2

if isunix()     

name = getenv('USER'); else name = getenv('username');

end

myinfo2 = [' ' name ' : *<< ' num2str(10000*rand(1,1)) ' >>* Final Examination Part 2']

%%%%%%% Copy this code exactly as it is ... do not modify it

b) Prompt the user to enter 2 complex numbers a and b using one input function and compare their absolute value or magnitude:

Print the following message if |a| < |b|     ‘a is less than b’

Print the following message if |a| > |b|     ‘a is greater than b’

Print the following message if | a| = |b|     ‘a is equal to b’

c) Check if the imaginary part is not zero and print the angle of both complex numbers.

d) Treat both complex numbers as vectors and create another vector named v that contains the sum of a and b.

e) Determine the dot product of both vectors (complex numbers a and b).

Explanation / Answer

Hello,
       Please find the answer attached below. If the answer has helped you please give a thumbs up rating. Thank you and have a nice day!

****** Matlab Code *****

%%%%%%% Copy this code exactly as it is ... do not modify it
%Final Examination…. PART #2
%if isunix()   
%name = getenv('USER'); else name = getenv('username');
%end
%myinfo2 = [' ' name ' : *<< ' num2str(10000*rand(1,1)) ' >>* Final Examination Part 2']
%%%%%%% Copy this code exactly as it is ... do not modify it

clc;
prompt = 'Please enter a complex number in x+yi format:';
a = input(prompt);
b = input(prompt);
ma = abs(a);
mb = abs(b);
if(ma<mb)
    fprintf('a is less than b. ');
elseif(ma>mb)
    fprintf('a is greater than b. ');
else
    fprintf('a is equal to b. ');
end

if(imag(a)==0)
    fprintf('Imaginary part of a is zero ');
end

if(imag(b)==0)
    fprintf('Imaginary part of b is zero ');
end

fprintf('Angle of a is: %f degrees ',angle(a)*180/pi);
fprintf('Angle of b is: %f degrees ',angle(b)*180/pi);

v = a + b;
fprintf('The vector sum of a and b is: %f + %fi ',real(v),imag(v));
fprintf('The dot product of a and b is %f ',real(a)*real(b)+imag(a)*imag(b))

***** Output *****

Please enter a complex number in x+yi format:4+3i
Please enter a complex number in x+yi format:7+2i
a is less than b.
Angle of a is: 36.869898 degrees
Angle of b is: 15.945396 degrees
The vector sum of a and b is: 11.000000 + 5.000000i
The dot product of a and b is 34.000000

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