Scilab
How to create a TABLE (roots of complex numbers) ?
Posts  1 - 1  of  1
Fengson
Hello,
I've got a problem.
My tast is to write a program that will count the roots of complex numbers. The problem is that the answer must be in a table, bacause it should look like this :

-->root(%i,4)
ans =
0.9238795 + 0.3826834i
- 0.3826834 + 0.9238795i
- 0.9238795 - 0.3826834i
0.3826834 - 0.9238795i

I've created a program, but it only displays several steps, and gives ONE answer, like this :

-->root(%i,4)
0.9238795 + 0.3826834i
- 0.3826834 + 0.9238795i
- 0.9238795 - 0.3826834i
0.3826834 - 0.9238795i
ans =
0.3826834 - 0.9238795i

Could anyone look at this and help me create a table that will make the answer like the first one ? Here is my code :

function [answer] = root(z,n)
answer= []
mod = ( sqrt( real(z)^2 + imag(z)^2 ) )
arg = asin( imag(z) / mod )

for i = 0 : n-1
radians = (%pi * 360 * i) / 180
odp = ( mod^(1/n) ) * ( cos( ( arg + radians ) / n ) + %i * sin( ( arg + radiany ) / n) )

answer = [odp]
disp(wynik)
end
endfunction

Save
Cancel
Reply
 
x
OK