Plotting magnitude of complex expression
Afficher commentaires plus anciens
The code I have used is as follows:
%Define constants
A_1=1;
A_2=2;
L=1;
%Specify range of k values to plot on x axis
k=[0:1:10];
%complex function to plot
t=(2*(A_1*A_2*cos(L*k) + A_1*A_2*sin(L*k)*1i))/(sin(L*k)*A_1^2*1i + 2*cos(L*k)*A_1*A_2 + sin(L*k)*A_2^2*1i);
%Finding magnitude of complex values
U=abs(t);
%Plot curve of U over specified range of k
plot(k,U);
I am looking to plot a graph of U on the y-axis, with k varying between 0 and 10 on the x axis. Having generated a matrix k of 11 integer values, the function t is only evaluated as a single complex number, rather than a matrix of complex numbers for each of the 11 input values of k. This means that the graph cannot be plotted since only a single point is generated.
Is there a mistake in my code which leads to t being a single value, rather than a range of values for varying k, which can then be plotted?
Many thanks for your help.
Réponse acceptée
Plus de réponses (1)
A_1=1;
A_2=2;
L=1;
evec = [];
For k = [0:0.1:10]
t=(2*(A_1*A_2*cos(L*k) + A_1*A_2*sin(L*k)*1i))/(sin(L*k)*A_1^2*1i + 2*cos(L*k)*A_1*A_2 + sin(L*k)*A_2^2*1i);
F = abs(t);
evec = [evec F];
U = evec;
end
plot(k',U');
1 commentaire
Srinidhi
le 13 Mar 2021
Hope this helps.
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
