Plotting a one dimensional curve in Maple with implicitplot3d - plot

I want to plot in Maple the solutions to the equation (x-y)^2+(1-z)^2=0.
However, implicitplot3d is not able to plot them, at least using the default arguments. Any recommendations?
I know a priori that the set of solutions is going to be a curve contained in a plane, because I want to plot solutions of equations of the form 'f(x,y)^2+(z-1)^2=0'. Where 'f(x,y)' is a polynomial.

If x, y, and z are all real then those two squares must both equal zero, and thus z=1.
In that case you can simply utilize the implicitplot command for a 2-D plot of f(x,y)=0, and if you wish you can transform that to a 3-D plot with z=1.
restart;
with(plots,display): with(plots,implicitplot):
with(plottools,transform):
eqn := (x-y)^2+(1-z)^2 = 0:
P2D := implicitplot(eval(eqn,z=1)):
display(transform((x,y)->[x,y,1])(P2D),
labels=[x,y,z]);
eqn := (x^2-y)^2+(1-z)^2 = 0:
P2D := plots:-implicitplot(eval(eqn,z=1)):
display(transform((x,y)->[x,y,1])(P2D),
labels=[x,y,z]);

Related

How to identify the roots of an equation by plotting it's real and imaginary parts

This is more of a general Maths question (might be silly even). But in high school we learn to identify the roots of an equation via it's plot right.
For example, for the equation
y = x^2 - 1
The blue line would show us the roots. This is when the blue line crosses x, so +- 1.
Now, if we said that the equation had a real and an imaginary part, so that it is
y = x^2 - 1 + (x^2 - 0.5)i
as given in the Mathematica screenshot, then we have a real part which crosses zero, and an imaginary part which also crosses zero but at a different x. So my question is: is it possible to identify the roots of such an equation by simply looking at the real and imaginary parts of the plot?
Note: part of my confusion is that if I use FindRoot, in Mathematica, I get either 0.877659 - 0.142424i or -0.877659 + 0.142424i. So might be some fundamental property in Maths I don't know about which prevents one from identifying roots of a complex function through separating real and imaginary parts...
we have a real part which crosses zero, and an imaginary part which also crosses zero but at a different x.
Those are graphs of the real and imaginary parts plotted for real values of x. If they both crossed the horizontal axis at the same point(s), that would mean the equation has real root(s), since both real and imaginary parts would be zero for some real value of x. However, this equation has no real roots, so the crossing points are different.
So my question is: is it possible to identify the roots of such an equation by simply looking at the real and imaginary parts of the plot?
f(x) = x^2 - 1 + i (x^2 - 0.5) is a complex function of a complex variable, which maps a complex variable x = a + i b to the complex value f(x) = Re(f(x)) + i Im(f(x)).
Each of Re(f(x)) and Im(f(x)) is a real function of a complex variable. Such functions can be plotted in 3D by representing x = a + i b as a point in the (a, b) plane, and the value of the function along the third dimension, say c. For example, f(x) has the following graphs for the real and imaginary parts.
The cross-sections of the two surfaces by the horizontal plane c = 0 are pairs of curves where each function is zero, respectively. It follows that the intersections of those curves are the points where Re(f(x)) = Im(f(x)) = 0, which means they are the roots of the equation f(x) = 0.
Since f(x) = 0 is a quadratic equation, it must have two roots, and those two points are in fact ±(0.877659 - 0.142424 i), as can be verified by direct calculation.

How to find whole distance between two points in a curved line in R?

I have a similar line graph plotted using R plot function (plot(df))
I want to get distance of the whole line between two points in the graph (e.g., between x(1) and x(3)). How can I do this?
If your function is defined over a fine grid of points, you can compute the length of the line segment between each pair of points and add them. Pythagoras is your friend here:
To the extent that the points are not close enough together that the function is essentially linear between the points, it will tend to (generally only slightly) underestimate the arc length.
Note that if your x-values are stored in increasing order, these ẟx and ẟy values can be obtained directly by differencing (in R that's diff)
If you have a functional form for y as a function of x you can apply the integral for the arc length -- i.e. integrate
∫ √[1+(dy/dx)²] dx
between a and b. This is essentially just the calculation in 1 taken to the limit.
If both x and y are parametric functions of another variable (t, say) you can simplify the parametric form of the above integral (if we don't forget the Jacobian) to integrating
∫ √[(dx/dt)²+(dy/dt)²] dt
between a and b
(Note the direct parallel to 1.)
if you don't have a convenient-to-integrate functional form in 2. or 3. you can use numerical quadrature; this can be quite efficient (which can be handy when the derivative function is expensive to evaluate).

MAPLE: Take the positive solution and plotting

I have these four equations:
eq1:= 1.6*10^(-7)*R*sin(t)-4.4*10^(-14)*R^2*cos(t)*sin(t)-1.6*10^(-14)*R^2*cos(t)^2+4.2*10^(-14)*R^2-1.3+2.1*10^(-9)*R*cos(t)=0;
eq2 := 8.3*10^(-8)*R*sin(t)-1.2*10^(-13)*R^2*cos(t)*sin(t)-2.9*10^(-44)*R^2*cos(t)^2+7.1*10^(-14)*R^2-1.3+8.3*10^(-8)*R*cos(t)=0;
eq3 := 8.3*10^(-8)*R*sin(t)-1.2*10^(-13)*R^2*cos(t)*sin(t)-2.2*10^(-44)*R^2*cos(t)^2+7.1*10^(-14)*R^2-1.3+8.3*10^(-8)*R*cos(t)=0;
eq4 := 2.1*10^(-9)*R*sin(t)-4.4*10^(-14)*R^2*cos(t)*sin(t)+1.6*10^(-14)*R^2*cos(t)^2+2.6*10^(-14)*R^2-1.3+1.6*10^(-7)*R*cos(t)=0;
I want to solve each equation for R, each obviously yielding two roots and I'm always assured that one root is above the horizontal axis while the other is below it, and pick only the four non-negative roots without doing it manually i.e. for instance, write something like res:=solve(eq1,R), plotting each one as a function of t and only then taking the positive root. I want the code to do it.
After obtaining the positive roots, say {r1,r2,r3,r4}, I want to plot on the same figure, the following 4 graphs
plot([r1*cos(t),r1*sin(t),t=0..2*Pi]);
plot([r2*cos(t),r2*sin(t),t=0..2*Pi]);
plot([r3*cos(t),r3*sin(t),t=0..2*Pi]);
plot([r4*cos(t),r4*sin(t),t=0..2*Pi]);
Finally, I need to outline the intersection area with some color and shade it.
I would appreciate your help.
Here is how to pick the positive root and how to iterate through your equations. From here I think you should be able to make the plots yourself. Just beware that your roots are "heavy" expressions.
restart:
with(plots):
# Number of equations
n := 4;
# Empty solution vector
solutions := Vector(n):
# List of equations
eq := [
1.6*10^(-7)*R*sin(t)-4.4*10^(-14)*R^2*cos(t)*sin(t)-1.6*10^(-14)*R^2*cos(t)^2+4.2*10^(-14)*R^2-1.3+2.1*10^(-9)*R*cos(t)=0 ,
8.3*10^(-8)*R*sin(t)-1.2*10^(-13)*R^2*cos(t)*sin(t)-2.9*10^(-44)*R^2*cos(t)^2+7.1*10^(-14)*R^2-1.3+8.3*10^(-8)*R*cos(t)=0 ,
8.3*10^(-8)*R*sin(t)-1.2*10^(-13)*R^2*cos(t)*sin(t)-2.2*10^(-44)*R^2*cos(t)^2+7.1*10^(-14)*R^2-1.3+8.3*10^(-8)*R*cos(t)=0 ,
2.1*10^(-9)*R*sin(t)-4.4*10^(-14)*R^2*cos(t)*sin(t)+1.6*10^(-14)*R^2*cos(t)^2+2.6*10^(-14)*R^2-1.3+1.6*10^(-7)*R*cos(t)=0
]:
# Iterate through all equations
for i from 1 to n do:
# Find and store positive root
solutions[i] := solve(eq[i], R, useassumptions) assuming R>0:
end do:
solutions;

Solve or plot the reverse of an equation in R

I plotted an expression curve, i.e.curve(-log((1-x)/0.9999)/x,ylim=c(0,4)).
However, I want to see the reverse relationship, i.e. y changes over x instead of x changes over y. Are there any R function can plot it automatically? Or a function that can solve the equation?
There are two obvious choices:
(i) derive the inverse function algebraically (trivial in this case),
That is, take y=-log((1-x)/0.9999) and make x the subject of the equation (which would require straightforward algebraic manipulation suitable for a question on math.SE if it's not obvious how to proceed)...
... and then use curve on the result of that, or
(ii) use plot rather than curve to plot a set of (x,y) pairs (set type="l" to get a curve), and simply interchange which is x and which is y in the call to plot.

Why is my plot3d white in SciLab?

t = 0:%pi/50:10*%pi;
plot3d(sin(t),cos(t),t)
When I execute this code the plot is done but the line is not visible, only the box. Any ideas which property I have to change?
Thanks
The third argument should, in this case, be a matrix of the size (length arg1) x (length arg2).
You'd expect plot3d to behave like an extension of plot and plot2d but it isn't quite the case.
The 2d plot takes a vector of x and a vector of y and plots points at (x1,y1), (x2,y2) etc., joined with lines or not as per style settings. That fits the conceptual model we usually use for 2d plots - charting the relationship of one thing as a function of another, in most cases (y = f(x)). THere are other ways to use a 2d plot: scatter graphs are common but it's easy enough to produce one using the two-rows-of-data concept.
This doesn't extend smoothly to 3d though as there are many other ways you could use a 3d plot to represent data. If you gave it three vectors of coordinates and asked it to draw a line between them all what might we want to use that for? Is that the most useful way of using a 3d plot?
Most packages give you different visualisation types for the different kinds of data. Mathematica has a lot of 3d visualisation types and Python/Scipy/Mayavi2 has even more. Matlab has a number too but Scilab, while normally mirroring Matlab, in this case prefers to handle it all with the plot3d function.
I think of it like a contour plot: you give it a vector of x and a vector of y and it uses those to create a grid of (x,y) points. The third argument is then a matrix whose dimensions match those of the (x,y) grid holding the z-coordinates of each point. The first example in the docs does what I think you're after:
t=[0:0.3:2*%pi]';
z=sin(t)*cos(t');
plot3d(t,t,z);
The first line creates a column vector of length 21
-->size(t)
ans =
21. 1.
The second line computes a 21 x 21 matrix of products of the permutations of sin(t) with cos(t) - note the transpose in the cos(t') element.
-->size(z)
ans =
21. 21.
Then when it plots them it draws (x1,y1,z11), (x1,y2,x12), (x2,y2,z22) and so on. It draws lines between adjacent points in a mesh, or no lines, or just the surface.

Resources