# Math Help - i need your help .......Matlab

1. ## i need your help .......Matlab

hey guys
i have a problem with Matlab i could not figure it out
i constructed a Matlab code that shows me all possible values of k and w relating to this equation
w=exp(2*pi*j*k/5) where k=0,1,2 ,3 ,4
so the expected result would be
k w
0 1
1 0.309 + j 0.951
2 -0.809 + j 0.5877
3 -0.809 - j 0.5877
4 0.309 - j 0.951

but the problems is my code does not show me the imaginary part , it shows me only the real part of W as shown in the attached file

2. Originally Posted by Zamorano
hey guys
i have a problem with Matlab i could not figure it out
i constructed a Matlab code that shows me all possible values of k and w relating to this equation
w=exp(2*pi*j*k/5) where k=0,1,2 ,3 ,4
so the expected result would be
k w
0 1
1 0.309 + j 0.951
2 -0.809 + j 0.5877
3 -0.809 - j 0.5877
4 0.309 - j 0.951

but the problems is my code does not show me the imaginary part , it shows me only the real part of W as shown in the attached file
Not the only thing wrong, but you are trying to print complex numbers using a real format. Try something like:

Code:

'k           re(w)           im(w)'

for k=0:4
w=exp(2*pi*k*j/5);
printf('%4.2f %14.6f %14.6f \n',k,real(w),imag(w));
end
CB

3. thank you CaptinBlack
but this is not the required
i want a Matlab code shows me both the real and imaginary parts as this form : w=a+jb
your code shows this form : w = a (imag) b

if you can give me an imaginary format for this program i will appreciated

thank you for ur cooperation

4. Originally Posted by Zamorano
thank you CaptinBlack
but this is not the required
i want a Matlab code shows me both the real and imaginary parts as this form : w=a+jb
your code shows this form : w = a (imag) b

if you can give me an imaginary format for this program i will appreciated

thank you for ur cooperation
Well Matlab (and C) do not support a format code for complex numbers so you will have to work something out for yourself if you wish to use fprintf or printf. Possibly using num2str to convert the complex numbers to strings for printing, or something like:

printf('%12.1f %+12.2fj \n',real(x),imag(x))

or:

printf('%s \n',num2str(x))

CB

5. Thanks CB