Hello, I am new and trying to plot the imaginary parts of a function, can anyone help?

Hello, I am trying to plot the imaginary parts of Kz against Kx from the equation:-
Kz^2 = 8c sin^2(DKx/2)[2c sin^2(DKx/2) - lambdaq0^2]
which i have written as
Kz = sqrt ( 8 .* c .* ( sin ( ( D .* Kx ) ./ 2 ) ) .^2 .* ( 2 .* c .* ( ( sin ( ( D .* Kx) ./ 2 ) ) .^2 ) - ( lambda .* ( q0.^2 ) ) ) )
where lambda, D, q0 and c are all constants.
and really, I have no idea where to start, can anyone help me?

Answers (2)

Hello, thanks for the quick reply. Let us assume that I am completely inept at using matlab and my code looks like this:-
"clear variables
Kx = linspace(0,6*pi,300); D = 2.6 * 10^-9; lambda = 0.5 ; c = 0.5; q0 = 0.01 ;
Kz = sqrt ( 8 .* c .* ( sin ( ( D .* Kx ) ./ 2 ) ) .^2 .* ( 2 .* c .* ( ( sin ( ( D .* Kx) ./ 2 ) ) .^2 ) - ( lambda .* ( q0.^2 ) ) ) );
imag_Kz = imag(Kz);
figure (1) plot (Kx, imag_Kz)"
Does much of this seem wrong?

1 Comment

Your code is fine.
you really are plotting the imaginary part of Kz against Kx.
Note : when you post some code here, use the button {}Code to format it and make it more readable.

This question is closed.

Asked:

on 26 Nov 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!