Is there any limitation with fimplicit and fimplicit3 when functions have sqrt ?
3 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Steven Lord
on 5 Mar 2021
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)
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 Comments
Walter Roberson
on 5 Mar 2021
touching zero is often a point and the fimplicit* draw lines not points.
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!