Dear all, I want to plot "z" vs. "kappa" where kappa is changing from 1 to 0. this is my @ff function:
function y = f(x)
y = (1/pi)*((0.1*x)-(((sqrt((1+x)./2)).*exp(1).^-(6*(sqrt(2*0.1*(1+x))))))*(kappa*(sqrt((1-x)/(1+x)))-(sqrt((1+x)/(1-x)))));
after that using fzero I want to find "z" for every single kappa in the region in order to get the plotted data:
fun = @ff; % function
x0 = 0; % initial interval
z = fzero(fun,x0);
now how can I create a loop to change kappa from 1 to 0 and get "z" for each of them on my plot. many Thanks in Advance,

 채택된 답변

Star Strider
Star Strider 2017년 11월 12일

1 개 추천

Try this:
f = @(x,kappa) (1/pi)*((0.1*x)-(((sqrt((1+x)./2)).*exp(-(6*(sqrt(2*0.1*(1+x))))))).*(kappa*(sqrt((1-x)./(1+x)))-(sqrt((1+x)./(1-x)))));
N = 10; % Length Of ‘kappa’ Vector
kappa = linspace(0, 1, N);
for k1 = 1:N
z(k1) = fzero(@(x) f(x, kappa(k1)), 1E-3);
end
figure(1)
plot(kappa, z)
xlabel('\kappa')
ylabel('z(\kappa)')
grid

댓글 수: 4

Hi again,
Now for this same equation. my Kappa is constant Kappa=0.1 I add "Delta_E" and "Lambda" to the equation and I want them to change( which I have written below). This time I want to draw a mesh plot for (Z, lambda, Delta_E). I would highly appreciate if you help me correct it:
kd = 6 ;
kappa = 0.1 ;
f = @(x,lambda) ((Delta_E)+(lambda*x)-(((sqrt((1+x)./2)).*exp(1).^(-(kd*(sqrt(2*lambda*(1+x))))))).*(kappa*(sqrt((1-x)./(1+x)))-(sqrt((1+x)./(1-x)))));
N = 100;
lambda = linspace(0.05,0.25, N);
Delta_E= linspace(0.1,0.35, N);
for k1 = 1:N
z(k1) = fzero(@(x) f(x, lambda(k1)), 1E-3);
end
figure(1)
mesh(lambda,Delta_E, z)
xlabel('\lambda')
ylabel('\delta E')
zlabel('Z')
grid
Star Strider
Star Strider 2017년 11월 27일
I am not certain what you are doing. If you want to find the zeros of a bivariate function, I would use the contour function. See the documentation on contour for details.
However yours is trivariate in ‘lambda’, ‘Delta_E’ and ‘x’, so that might not work. You could do a nested loop through ‘lambda’ and ‘Delta_E’ using fzero. That might be the only way to approach this.
fartash2020
fartash2020 2017년 11월 28일
Thanks Star Strider, but how can I create a nested loop?
Try this:
N = 100;
kd = 6;
kappa = 0.1;
lambda = linspace(0.05,0.25, N);
Delta_E = linspace(0.1,0.35, N);
[Lm,DE] = meshgrid(lambda, Delta_E);
f = @(x,lambda,Delta_E) ((Delta_E)+(lambda*x)-(((sqrt((1+x)./2)).*exp(-(kd*(sqrt(2*lambda*(1+x))))))).*(kappa*(sqrt((1-x)./(1+x)))-(sqrt((1+x)./(1-x)))));
for k1 = 1:length(lambda)
for k2 = 1:length(Delta_E)
z(k1,k2) = fzero(@(x) f(x,lambda(k1),Delta_E(k2)), rand);
end
end
figure(1)
mesh(lambda, Delta_E, z)
You might find it worthwhile to plot the absolute value of ‘z’, because the results are complex when they are not NaN, although the plot itself reveals little.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

질문:

2017년 11월 12일

댓글:

2017년 11월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by