MatLab: Urgent, your help is needed! Mathematically, if z_1 = a_1 + b_1 i and z_
ID: 3765948 • Letter: M
Question
MatLab: Urgent, your help is needed!
Mathematically, if z_1 = a_1 + b_1 i and z_2 = a_2 + b_2 I are two (non-zero) complex numbers, then their quotient is z_1/z_2 = z_1z_2/|z_2|^2, where z_2 = a_2 - b_2 I is the complex conjugate of z_2, and |z_2|^2 = z_2z_2 is the modulus of z_2. As usual, I is the complex unit which satisfies i^2 = -1. In class on November 10, we wrote two functions called cplxadd.m and cplxmul.m whose purposes were to add and multiply two complex numbers, respectively. Both functions treated a complex number as a struct class variable with two fields: real and imag. Your job here is to write a Mat lab function called cplxdiv.m whose purpose is to calculate the quotient of two complex numbers. As with cplxadd.m and cplxmul.m, your function must take 2 struct class inputs (each with the same 2 fields: real and imag), and produce a struct class output with those same 2 fields. For your convenience, I have included the functions from class on November 10 with this assignment. To test your function, given the two struct variables the function calls c=cplxdiv(a,b) and d=cplxdiv(b,a) should, respectively, produce the outputExplanation / Answer
function cplxdiv
function d = cplxdiv(a,b)
d = Complex;
con_b = Complex;
con_b.real = b.real;
con_b.imag = b.imag;
ans = cplxmul(a,con_b);
mod_b = sqrt(b.real*b.real + b.imag*b.imag);
ans.real = ans.real/mod_b;
end
rest script
classdef Complex
properties
real
imag
end
end
a = Complex;
a.real = -2;
b.imag = 3;
b = Complex;
b.real = 1;
b.imag = 2;
c = cplxdiv(a,b)
d = cplxdiv(b,a)