Ploting vector perpendicular to a surface in a specific point
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Diego Lazcano Colodrero
am 21 Aug. 2020
Kommentiert: Diego Lazcano Colodrero
am 21 Aug. 2020
Hello.
I want to plot the gradient of a surface in a specific point.
I know the gradient is perpendicular to the level curve of a
defined function like:


chosing a z and determinating the points of the pairs
we can obtain the slope of the tangent in a two dimension plane, and it works fine.

The problem is in the 3D plot. I make the function
, so i have the "level surface 0", and i want the orthogonal vector at the point
. So, by theory,
gives me the orthogonal vector at
.







These, also, are the coefficients of the tangent plane
.

The surface is perfect ploted, the tangent plane too, but i can't plot the orthogonal vector at
, and the vector value is the gradient value
. I thought that quiver3 with the arguments
and
it was going to work. At this point i have tried several proccedures but none of them returns me the surface orthogonal vector.




Here is my code, (the error is at almost the end of the code in the quiver3 function)
clear;
clc;
close all;
% https://la.mathworks.com/help/matlab/math/calculate-tangent-plane-to-surface.html?lang=en
% function definition
f = @(x,y) x.^2 + y.^2;
% creating the mesh
DD = .5;
[xx,yy] = meshgrid(-10:DD:10);
% dfx & dfy are numerical approx to the gradient
[dfx,dfy] = gradient(f(xx,yy),DD);
% Point to be plot the tangent plane and the perpendicular vector
x0 = 1;
y0 = 2;
% looking for the value of the gradient at the point x0,y0
t = (xx == x0) & (yy == y0);
indt = find(t); % retunrs the index position of x0 and y0
% numeric value of the gradient in the position
dfx0 = dfx(indt);
dfy0 = dfy(indt);
% tangent plane definition
z = @(x,y) f(x0,y0) + dfx0*(x-x0) + dfy0*(y-y0);
hh = figure(1);
set(hh,'color','w','Position',[1920*.4 1080*.5 1920*.5 1080*.4])
subplot(1,2,1)
% plot the function
surf(xx,yy,f(xx,yy),'EdgeAlpha',0.7,'FaceAlpha',0.9)
view(3)
hold on
% plot the tangent plane
surf(xx,yy,z(xx,yy))
hold off;
axis([-10 10 -10 10 0 100])
subplot(1,2,2)
surf(xx,yy,f(xx,yy),'EdgeAlpha',0.7,'FaceAlpha',0.9)
hold on
surf(xx,yy,z(xx,yy))
plot3(1,2,f(1,2),'ro','MarkerSize',17,'MarkerEdgeColor','red','MarkerFaceColor',[1 .6 .6]);
% ------- HERE IS THE ERROR --------
quiver3(x0,y0,f(x0,y0),dfx0,dfy0,-1,0); % -> here is the error
% ------- I THINK IS THE QUIVER FUNCTION MY PROBLEM -------
view(3)
hold off;
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 21 Aug. 2020
Bearbeitet: Bruno Luong
am 21 Aug. 2020
You are tricked by the scaling. If you want to observe the orthogonal by eye you should set the same scaling for x-y-z
quiver3(x0,y0,f(x0,y0),dfx0,dfy0,-1,0); % -> here is the error
% ------- I THINK IS THE QUIVER FUNCTION MY PROBLEM -------
axis equal % <=== HERE FIX YOUR "PROBLEM"
view(3)
You course your parabolid is going high, si x-y plane will shrink relatively.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!