Plotting a parametric surface

9 views (last 30 days)
Tonny
Tonny on 22 Dec 2013
Commented: Roger Stafford on 22 Dec 2013
Hi guys,
I've been having trouble figuring this out. I'm suppose to plot a parabolic surface of this general eqn on Matlab GUI:
A = sqrt((X-X1)^2 + (Y-Y1)^2 + (Z-Z1)^2) - sqrt((X-X2)^2 + (Y-Y2)^2 + (Z-Z2)^2)
The equation only stands when realistic values of the variables are given. Thus using meshgrid method doesn't work.
So i'm thinking of using parametric equations to solve it by making all X, Y and Z in terms of t.
Any idea which plot should i be using? ezsurf? plot3? Thanks a ton!
  1 Comment
Roger Stafford
Roger Stafford on 22 Dec 2013
That isn't a parabolic surface, it is one branch of a hyperbola of revolution. The two points (X1,Y1,Z1) and (X2,Y2,Z2) are the two focal points and the axis of revolution lies along the line between them.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 22 Dec 2013
What are "realistic values of the variables"? Is "A" a constant?
If you use meshgrid to calculate an output, you can set the output to NaN at the places that are not relevant.
The kind of plot to use is going to depend on whether "A" is constant or not. If it is not, then you have 3 independent variables together with one output value, leading to a 4D plot. The 4th dimension would have to be represented by something like color or marker shape. But if "A" is a constant then you only have 2 independent variables and so can construct surfaces.
  4 Comments
Walter Roberson
Walter Roberson on 22 Dec 2013
Expressing it without t is not bad. The following is semi-optimized code. t103A and t103B are the two solutions, which differ in the sign of 't81'.
You would ndgrid to get X, Y, Z, and you would calculate these, and you would use
t103A(imag(t103A) ~= 0) = 0;
t103B(imag(t103B) ~= 0) = 0;
after which you should be able to surf(t103A); hold on; surf(t103B)
t2 = (A .^ 2);
t4 = (t2 .^ 2);
t5 = (X .^ 2);
t7 = (X1 + X2);
t9 = (X1 .^ 2);
t10 = 2 .* t9;
t11 = (X2 .^ 2);
t12 = 2 .* t11;
t13 = (Y .^ 2);
t15 = (Y1 + Y2);
t17 = (Y1 .^ 2);
t18 = 2 .* t17;
t19 = (Y2 .^ 2);
t20 = 2 .* t19;
t21 = (Z1 .^ 2);
t23 = (Z1 .* Z2);
t25 = (Z2 .^ 2);
t27 = 4 .* X .* t7 + 4 .* Y .* t15 - t10 - t12 - 4 .* t13 - t18 - t20 - 2 .* t21 + 4 .* t23 - 2 .* t25 - 4 .* t5;
t29 = 4 .* t21;
t30 = 8 .* t23;
t31 = 4 .* t25;
t32 = (X1 - X2);
t33 = (t32 .^ 2);
t37 = (Y1 - Y2);
t46 = t9 - t11 + t17 - t19;
t51 = (t37 .^ 2);
t64 = t21 .^ 2;
t65 = t21 .* Z1;
t75 = t25 .^ 2;
t78 = t46 .^ 2;
t79 = t4 + t2 .* t27 + t5 .* (t29 - t30 + t31 + 4 .* t33) + X .* (8 .* Y .* t32 .* t37 + 8 .* Z1 .* t7 .* Z2 - 4 .* t21 .* t7 - 4 .* t25 .* t7 - 4 .* t46 .* t32) + t13 .* (t29 - t30 + t31 + 4 .* t51) + Y .* (8 .* Z1 .* t15 .* Z2 - 4 .* t21 .* t15 - 4 .* t25 .* t15 - 4 .* t46 .* t37) + t64 - 4 .* Z2 .* t65 + t21 .* (t10 + t12 + t18 + t20 + 6 .* t25) - 4 .* Z1 .* (t9 + t11 + t17 + t19 + t25) .* Z2 + t75 + 2 .* t25 .* (t9 + t11 + t17 + t19) + t78;
t81 = sqrt((t79 .* t2));
t84 = 2 .* X .* X1;
t86 = 2 .* X .* X2;
t88 = 2 .* Y .* Y1;
t90 = 2 .* Y .* Y2;
t103A = 10 ./ (A - Z1 + Z2) ./ (A + Z1 - Z2) .* ((t2 .* (Z1 + Z2)) + t81 - t65 + (Z2 .* t21) + (Z1 .* (t84 - t86 - t9 + t11 + t88 - t90 - t17 + t19 + t25)) - (t25 .* Z2) + (Z2 .* (-t84 + t86 + t9 - t11 - t88 + t90 + t17 - t19))) ./ 20;
t103B = 10 ./ (A - Z1 + Z2) ./ (A + Z1 - Z2) .* ((t2 .* (Z1 + Z2)) - t81 - t65 + (Z2 .* t21) + (Z1 .* (t84 - t86 - t9 + t11 + t88 - t90 - t17 + t19 + t25)) - (t25 .* Z2) + (Z2 .* (-t84 + t86 + t9 - t11 - t88 + t90 + t17 - t19))) ./ 20
Tonny
Tonny on 22 Dec 2013
Edited: Tonny on 22 Dec 2013
I'm still rather confused. Pardon me for it as I'm still quite new to Matlab.
I first approach to solve it by finding the eqn of Y and setting a range of values for X and Z. The rest of the variables are constant. The equation of Y is solved using the Matlab eqn solver.
>> syms A X Y Z X_r1 X_r2 Y_r1 Y_r2 Z_r1 Z_r2
>> solve(sqrt((X-X_r1)^2 + (Y-Y_r1)^2 + (Z-Z_r1)^2) - sqrt((X-X_r2)^2 + (Y-Y_r2)^2 + (Z-Z_r2)^2) - A, Y)
And get:
(A.*(A.^4 - 4.*A.^2.*X.^2 + 4.*A.^2.*X.*X_r1 + 4.*A.^2.*X.*X_r2 - 2.*A.^2.*X_r1.^2 - 2.*A.^2.*X_r2.^2 - 2.*A.^2.*Y_r1.^2 + 4.*A.^2.*Y_r1.*Y_r2 - 2.*A.^2.*Y_r2.^2 - 4.*A.^2.*Z.^2 + 4.*A.^2.*Z.*Z_r1 + 4.*A.^2.*Z.*Z_r2 - 2.*A.^2.*Z_r1.^2 - 2.*A.^2.*Z_r2.^2 + 4.*X.^2.*X_r1.^2 - 8.*X.^2.*X_r1.*X_r2 + 4.*X.^2.*X_r2.^2 + 4.*X.^2.*Y_r1.^2 - 8.*X.^2.*Y_r1.*Y_r2 + 4.*X.^2.*Y_r2.^2 - 4.*X.*X_r1.^3 + 4.*X.*X_r1.^2.*X_r2 + 4.*X.*X_r1.*X_r2.^2 - 4.*X.*X_r1.*Y_r1.^2 + 8.*X.*X_r1.*Y_r1.*Y_r2 - 4.*X.*X_r1.*Y_r2.^2 + 8.*X.*X_r1.*Z.*Z_r1 - 8.*X.*X_r1.*Z.*Z_r2 - 4.*X.*X_r1.*Z_r1.^2 + 4.*X.*X_r1.*Z_r2.^2 - 4.*X.*X_r2.^3 - 4.*X.*X_r2.*Y_r1.^2 + 8.*X.*X_r2.*Y_r1.*Y_r2 - 4.*X.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_r1.^2 - 4.*Y_r1.*Y_r2.*Z_r2.^2 + Y_r2.^4 + 4.*Y_r2.^2.*Z.^2 - 4.*Y_r2.^2.*Z.*Z_r1 - 4.*Y_r2.^2.*Z.*Z_r2 + 2.*Y_r2.^2.*Z_r1.^2 + 2.*Y_r2.^2.*Z_r2.^2 + 4.*Z.^2.*Z_r1.^2 - 8.*Z.^2.*Z_r1.*Z_r2 + 4.*Z.^2.*Z_r2.^2 - 4.*Z.*Z_r1.^3 + 4.*Z.*Z_r1.^2.*Z_r2 + 4.*Z.*Z_r1.*Z_r2.^2 - 4.*Z.*Z_r2.^3 + Z_r1.^4 - 2.*Z_r1.^2.*Z_r2.^2 + Z_r2.^4).^(1./2) + A.^2.*Y_r2 - X_r1.^2.*Y_r1 + X_r1.^2.*Y_r2 + X_r2.^2.*Y_r1 - X_r2.^2.*Y_r2 + Y_r1.*Y_r2.^2 + Y_r1.^2.*Y_r2 - Y_r1.*Z_r1.^2 + Y_r1.*Z_r2.^2 + Y_r2.*Z_r1.^2 - Y_r2.*Z_r2.^2 - Y_r1.^3 - Y_r2.^3 + 2.*X.*X_r1.*Y_r1 - 2.*X.*X_r1.*Y_r2 - 2.*X.*X_r2.*Y_r1 + 2.*X.*X_r2.*Y_r2 + 2.*Y_r1.*Z.*Z_r1 - 2.*Y_r1.*Z.*Z_r2 - 2.*Y_r2.*Z.*Z_r1 + 2.*Y_r2.*Z.*Z_r2)./(2.*A.^2 - 2.*Y_r1.^2 + 4.*Y_r1.*Y_r2 - 2.*Y_r2.^2)
Xn = 1:100;
Zn = -100:0;
[X,Z] = meshgrid(Xn,Zn);
I meshgrid X and Z and plot Y. The issue comes about when some values of Y are imaginary, which was not expected. So i assume it's due to force plotting of meshgrid. Since surf() can't plot complex numbers, i use real(Y1) and real(Y2) instead. Graph came out like in pic1.
Next i made the imaginary numbers to Nan and it become like in pic 2.
So there is a missing region in the center which is suppose to be relevant.
The graph i'm expecting to have is like pic2, but with the center region not missing.

Sign in to comment.

Categories

Find more on Line Plots 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!