46 views (last 30 days)

Show older comments

Hi,

I'm having some problems trying to plot the following implicit equation f1 = @(x,y) sqrt(L^2-(R*(cosd(x)-sind(x).*sind(y))-H).^2) with fimplicit(f1).

If I use the following code, in the plot nothing appears:

R = 0.35;

L = 0.25;

H = 0.4;

f1 = @(x,y) sqrt(L^2-(R*(cosd(x)-sind(x).*sind(y))-H).^2);

fimplicit(f1,[-90 90 -90 90])

I have no problem if I remove the square root, so I guess is due to the imaginary solutions. Using fsurf(f1) I do see some real solutions and I would like to plot them. Is there any way to plot only the real solutions without removing the sqrt ?

Thank you in advance.

Star Strider
on 23 Feb 2021

Nothing is being generated:

R = 0.35;

L = 0.25;

H = 0.4;

f1 = @(x,y) sqrt(L^2-(R*(cosd(x)-sind(x).*sind(y))-H).^2);

figure

hfi = fimplicit(f1,[-90 90 -90 90]);

x = hfi.XData

y = hfi.YData

z = hfi.ZData

produces:

x =

1×0 empty double row vector

y =

1×0 empty double row vector

z =

1×0 empty double row vector

However:

figure

hfc = fcontour(f1,[-90 90 -90 90]);

LL = hfc.LevelList;

shows that there are no contours at 0. Forcing a contour at 0 creates a blank plot.

Star Strider
on 23 Feb 2021

My pleasure!

That’s also what I found.

If you want to experiment with the real, imag and abs values, make the appropriate function calls in this version of the fcontour call:

hfc = fcontour(@(x,y)real(f1(x,y)),[-90 90 -90 90]);

hfc = fcontour(@(x,y)imag(f1(x,y)),[-90 90 -90 90]);

hfc = fcontour(@(x,y)abs(f1(x,y)),[-90 90 -90 90]);

I did not specifically analyse the behaviour of the function beyond these experiments. (The output permits setting different options and querying the result for the data the function generates.)

John D'Errico
on 23 Feb 2021

Edited: John D'Errico
on 23 Feb 2021

First, look at what you have.

R = 0.35;

L = 0.25;

H = 0.4;

syms x y

F = sqrt(L^2-(R*(cosd(x)-sind(x).*sind(y))-H).^2)

The sqrt is irrelevant, since you are looking for a zero, but things are simpler if we just drop the sqrt.

F2 = L^2-(R*(cosd(x)-sind(x).*sind(y))-H).^2

Now, look for the solution locus. I'll expand the region to a larger interval in x and y, just to see if you missed anything with the narrow domain.

fimplicit(F2,[-180,180, -180 180])

So real solutions do exist. They appear to be sinusoidal curves. And solutions do exist in the domain you specified.

There is no need to worry about complex solutions. There are very real solutions.

ysol = solve(F2 == 0,y,'returnconditions',true)

ysol.y

ysol.parameters

ysol.conditions

So as a function of x, we can find 4 primary solutions for any given x, although for SOME values of x, there may be no real solutions. For example, when x is any integer multiple of 180 degrees, it should be quite clear that no finite solutions can exist, since you would have a divide by zero. And for some values of x, the argument to asin will be greater than 1 or less than -1. In those cases, asin will produce complex results.

Finally, there will be infinitely many solutions, since the solution is a function of an integer parameter k.

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

Start Hunting!