Write a program that creates a class for complex numbers. A complex number is a number of the form a + bi, where a is the real
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:11| Question number:11.11
All Answers
total answers (1)
Complex.m
classdef Complex
properties
realpart = 0;
imagpart = 0;
end
methods
function obj = Complex(rp, ip)
if nargin == 2
obj.realpart = rp;
obj.imagpart = ip;
end
end
function disp(obj)
fprintf('%.1f + %.1fi\n', obj.realpart, obj.imagpart)
end
end
end
>> compnum = Complex(2,4)
compnum =
2.0 + 4.0i
>>
need an explanation for this answer? contact us directly to get an explanation for this answer