Is there any limitation with fimplicit and fimplicit3 when functions have sqrt ?

3 ビュー (過去 30 日間)
Paul
Paul 2021 年 3 月 5 日
コメント済み: Walter Roberson 2021 年 3 月 5 日
Hi,
I have issues when calculating the values of x and y that make fun = @(psi,theta) (L^2-(R*(cos(theta)-sin(theta).*sin(psi))-H).^2).^(1/2) equal to zero. And I don't know if this is due to the square root. Cause, when taking out the square root there is no problem in the calculation.
This is driving me crazy since if you have a funcition, g(x,y) which is g(x,y) = sqrt(f(x,y)) and you are trying to find the values of x,y that make g(x,y) = 0, those are, at least, equal to those x, y values that make f(x,y) = 0. But according to MATLAB there are not values of x,y (nothing appears in the plot of figure 4 and figure 5).
The code is the following one:
R = 0.35;
L = 0.264;
H = 0.4;
% Trying first without the square root:
fun = @(psi,theta) (L^2-(R*(cos(theta)-sin(theta).*sin(psi))-H).^2);
figure(1)
hfi = fimplicit(fun, [-pi/2 pi/2 -pi/2 pi/2]);
xlabel('\psi (rad)');
xticks(-pi/2:pi/4:pi/2);
ylabel('\theta (rad)');
figure(2)
fimplicit3(fun, [-pi/2 pi/2 -pi/2 pi/2 0.3 0.8]);
xlabel('\psi (rad)');
ylabel('\theta (rad)');
zlabel('z (m) ');
figure(3)
hfc = fcontour(fun,[-pi/2 pi/2 -pi/2 pi/2]);
LL = hfc.LevelList;
% However, if the function contains a square root...
fun = @(psi,theta) (L^2-(R*(cos(theta)-sin(theta).*sin(psi))-H).^2).^(1/2);
figure(4)
fimplicit(fun, [-pi/2 pi/2 -pi/2 pi/2]) % PROBLEM !!!!!!!!!!!!!
figure(5)
fimplicit3(fun, [-pi/2 pi/2 -pi/2 pi/2 0.3 0.8]) % PROBLEM !!!!!!!!!!!!!
figure(6)
fcontour(fun)
xlabel('\psi (rad)');
ylabel('\theta (rad)');
% I also try to use mesh() in order to see what's happening... but as I said if g(x,y) = sqrt(f(x,y)) -> g(x,y) = 0 when f(x,y) = 0.
x= linspace(-pi/2,pi/2,100); y = linspace(-pi/2, pi/2, 100);
[X,Y] = meshgrid(x,y);
values = fun(X,Y);
values1 = values;
values1(imag(values1)~= 0) = NaN;
figure(8)
mesh(X,Y,values1);
xlabel('\psi (rad)');
ylabel('\theta (rad)');
zlabel('z (m)');
However for the case fun = @(psi,theta) (sin(psi).*sin(theta)).^(1/2) there is no problem with fimplicit3 but the error with fimplicit() mantains. Any suggestion to obtain the plot or the values without taking out the root?
I know that in this case, to avoid the problem, you can take out the square root, but for other cases or when you don't realize about that...
Thank you and sorry for the long message.

回答 (1 件)

Steven Lord
Steven Lord 2021 年 3 月 5 日
Let's look at the value of your function at one of the corners of the region on which you want to plot:
R = 0.35;
L = 0.264;
H = 0.4;
fun = @(psi,theta) (L^2-(R*(cos(theta)-sin(theta).*sin(psi))-H).^2).^(1/2);
fun(-pi/2, -pi/2)
ans = 0.0000 + 0.7020i
If the x coordinate is -pi/2 and the y coordinate is -pi/2, where on the 3-d axes below should z = 0 + 0.7020i be plotted?
view(3)
axis(pi/2*[-1 1 -1 1 -1 1])
xlabel('x')
ylabel('y')
zlabel('z')
grid on
  4 件のコメント
Paul
Paul 2021 年 3 月 5 日
編集済み: Paul 2021 年 3 月 5 日
Oh, I see the difference. Thank you so much.
f = @(x, y) x.^2+y.^2;
fimplicit(f)
% No plot appears in the figure
There is no plot, since as you say the function only touches zero. Cause for real solutions is always positive.That makes sense.
Although, that doesn't justify why there is nothing plotted in fimplict3()...cause when the function is f = @ (theta, psi) sqrt(sin(psi).*sin(theta)) there is no fimplicit (for the reason you perfectly explained) but there is fimplicit3().
Therefore, why in the case of f = @(psi,theta) sqrt(L^2-(R*(cos(theta)-sin(theta).*sin(psi))-H).^2) there is not fimplicit3().
If both, fimplicit() and fimplicit3(), don't work, how do you plot the values where the function touches zero when you have the square root, is there any Matlab command ? Or code ?
Any suggestions you have would be highly appreciated.
Walter Roberson
Walter Roberson 2021 年 3 月 5 日
touching zero is often a point and the fimplicit* draw lines not points.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by