Created
February 14, 2022 12:35
-
-
Save ArnyminerZ/6522eecc61b675fbce7828e246a980df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=-2; b=4; % El rango del cuadrado primero | |
side=20; % El tamaño del lado | |
h=(-a+b)/side; % Obtenemos el rango | |
x=a:h:b; | |
a=-2; b=4; % El rango del cuadrado primero | |
side=20; % El tamaño del lado | |
k=(-a+b)/side; % Obtenemos el rango | |
y=a:h:b; | |
% Si está a 0, se mostrará el gradiente, si no, no se mostrará | |
disable_gradient=1; | |
% Si está a 0, se mostrará la gráfica en 3D, si no, no se mostrará | |
disable_3d=1; | |
% Si está a 0, se mostrarán las curvas de nivel, si no, no se mostrará | |
disable_level=0; | |
% Si está a 0, se mostrará la malla | |
disable_mesh=1; | |
f=@(x,y)2*x.^2-x*y-3*y.^2-3.*x+7*y; | |
Ejercicio5_Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Creamos la malla | |
[X,Y]=meshgrid(x,y); | |
% Computamos Z | |
Z=f(X,Y); | |
% Dibujamos la malla | |
if disable_mesh == 0 | |
surf(X,Y,Z); | |
xlabel('X'), ylabel('Y'); | |
end | |
% Dibujamos las curvas de nivel | |
if disable_level == 0 | |
hold on | |
contour(X,Y,Z), | |
hold off | |
end | |
% Calculamos el gradiente aproximado usando gradient | |
if disable_gradient == 0 | |
hold on | |
[Zx,Zy]=gradient(Z,h,k); | |
quiver(X,Y,Zx,Zy) | |
axis equal tight | |
grid | |
hold off | |
end | |
% Dibujamos la función sobre el gradiente | |
if disable_3d == 0 | |
hold on | |
surf(X,Y,Z); | |
hold off | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment