Contour plot of a function

Please someone should with a contour plot of a p for various values of xi and H. For instance, H=0..3, and xi=2.0..0.0, where H is the x-axis, xi is the y-axis and p is the height of the contour. I need r to compute p, that is why write the expression for r.
for i = 1:m
q = x +i*y;
r(i)=q-(1-alpha)*tan(q)+(alpha3*xi*alpha/eta1)./(4*k1*q.^2/d^2-alpha3*xi/eta1).*tan(q)...
+ ((chi_a*H.^2*alpha)./(4*k1*q.^2/d^2-alpha3*xi/eta1 - chi_a*H.^2)).*tan(q);
end
for i=1:m
p(i) = gamma1*alpha/(4*k1*(r(i).^2)/d^2-alpha3*xi/eta1);
end

Respuestas (1)

Torsten
Torsten el 1 de Sept. de 2022
Editada: Torsten el 1 de Sept. de 2022

0 votos

H = 0:0.01:3;
XI = 0:0.01:2;
for i=1:numel(H)
h = H(i);
for j=1:numel(XI)
xi = XI(j);
for k=1:m
q = x +k*y;
r = q-(1-alpha)*tan(q)+(alpha3*xi*alpha/eta1)./(4*k1*q.^2/d^2-alpha3*xi/eta1).*tan(q)...
+ ((chi_a*H.^2*alpha)./(4*k1*q.^2/d^2-alpha3*xi/eta1 - chi_a*H.^2)).*tan(q);
p(i,j,k) = gamma1*alpha/(4*k1*(r^2)/d^2-alpha3*xi/eta1);
end
end
end
Now p is 3-dimensional instead of 2-dimensional as required for a contour plot. What now ?

5 comentarios

University Glasgow
University Glasgow el 1 de Sept. de 2022
Thank you for your response. It seems you changed q=x+i*y. q is complex number here. How is x+i*y = x+k*y? Does matlab sees k as imaginary?
Torsten
Torsten el 1 de Sept. de 2022
Editada: Torsten el 1 de Sept. de 2022
You have a loop over i in your code to determine r(i) - thus the loop index is taken for i and not the complex unit.
If you want to use the complex unit, use
q = x +1i*y;
instead of
q = x +k*y;
in the above code.
In this case I wonder why you need a loop over i in your code - the index i appears nowhere in the expression for r(i).
University Glasgow
University Glasgow el 1 de Sept. de 2022
Thank you. I think I understand what is happening.
Torsten
Torsten el 1 de Sept. de 2022
So you have x1, x2, H and xi given over an interval of values and thus r (resp. p) depending on 4 parameters. If you want to plot a surface over H and xi, you must set x1 and x2 to a constant value and do the same for H and xi what you did for x1 and x2 in your code from above.
Torsten
Torsten el 1 de Sept. de 2022
@University Glasgow comment moved here:
Okay, thank you

Iniciar sesión para comentar.

Productos

Versión

R2022a

Preguntada:

el 1 de Sept. de 2022

Comentada:

el 1 de Sept. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by