Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear;
- mtlb_fprintf(" ");
- mtlb_fprintf("*-------------------*");
- mtlb_fprintf("* *");
- mtlb_fprintf("* COMPLEX CONVERTER *");
- mtlb_fprintf("* *");
- mtlb_fprintf("*-------------------*");
- mtlb_fprintf(" ");
- flag = 1;
- while flag == 1 then
- clear;
- mtlb_fprintf("Rectangular to Polar -> 1");
- mtlb_fprintf("Polar to Rectangular -> 2");
- mtlb_fprintf("-----");
- _option = input("> Which operation? (1|2) -> ", "s");
- mtlb_fprintf(" ");
- if _option=='1' then
- // data for conversion to polar
- _real = input("> Real part = ");
- _imag = input("> Imaginary part = ");
- _mod = ((_real)^2 + (_imag)^2)^(1/2)
- _angle = atand(_imag/_real)
- mtlb_fprintf(" ");
- mtlb_fprintf("- Polar Form: %.2f < %.2f° \n",_mod, _angle);
- elseif _option=='2' then
- // data for conversion to rectangular
- _mod = input("> Module = ");
- _angle = input("> Angle = ");
- _real = (_mod) * (cos(_angle*0.0174)) // cos operates with rad angle - multiplying for 3.14/180 = 0.0174 (converts degree to rad)
- _imag = (_mod) * (sin(_angle*0.0174)) // sin operates with rad angle - multiplying for 3.14/180 = 0.0174 (converts degree to rad)
- mtlb_fprintf(" ");
- if _imag==0 | _imag>0 then
- mtlb_fprintf("- Rectangular Form: %.2f + %.2fj\n", _real, _imag);
- else
- mtlb_fprintf("- Rectangular Form: %.2f - %.2fj\n", _real, _imag*(-1)); // adjusting the imaginary negative value to fit into the hard coded (-) signal
- // abs function doesn't work well with the float precision
- end
- end
- mtlb_fprintf(" ");
- mtlb_fprintf("-------------");
- answer = input(">> New operation? (y|n) -> ", "s")
- if answer=="Y" | answer=="y" then
- flag=1;
- mtlb_fprintf(" ");
- elseif answer=="N" | answer=="n" then
- flag=0;
- exit;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement