how to plot two nonlinear functions
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Muhammad Asad
le 31 Août 2024
Réponse apportée : Muhammad Asad
le 1 Sep 2024
how to plot two nonlinear eqations:
I have writeen two equations below
equations = @(x) [x(1).^2+x(1)*x(2)-10;x(2)+3*x(1)*x(2).^2-57];
i want to plot now them both togatherover the intervals [-10 10] for x(1) and [0 20] for x(2)
thanks
0 commentaires
Réponse acceptée
Sam Chak
le 31 Août 2024
Modifié(e) : Sam Chak
le 31 Août 2024
The bivariate equations descibe the surfaces. Are you expecting plots like the following?
Edit: Correcting the dot-product mistakes in the equations.
x1 = linspace(-10, 10, 51);
x2 = linspace( 0, 20, 51);
[X1, X2] = meshgrid(x1, x2);
Y1 = X1.^2 + X1.*X2 - 10;
Y2 = X2 + 3*X1.*(X2.^2) - 57;
figure
surf(X1, X2, Y1), xlabel('x_{1}'), ylabel('x_{2}'), zlabel('y_{1}')
title('Surface y_{1}')
figure
surf(X1, X2, Y2), xlabel('x_{1}'), ylabel('x_{2}'), zlabel('y_{2}')
title('Surface y_{2}')
2 commentaires
Sam Chak
le 31 Août 2024
Hi @Muhammad Asad, You can follow @Torsten's solution to plot the intersection between two surfaces.
Plus de réponses (2)
Torsten
le 31 Août 2024
Modifié(e) : Torsten
le 31 Août 2024
x = -10:0.1:10;
y = 0:0.1:20;
[X,Y] = meshgrid(x,y);
Z1 = X.^2+X.*Y-10;
Z2 = Y+3*X.*Y.^2-57;
% Visualize the two surfaces
surface(X,Y,Z1, 'FaceColor', [0.5 1.0 0.5], 'EdgeColor', 'none');
surface(X,Y,Z2, 'FaceColor', [1.0 0.5 0.0], 'EdgeColor', 'none');
view(3); camlight; axis vis3d
% Take the difference between the two surface heights and find the contour
% where that surface is zero.
zdiff = Z1 - Z2;
C = contours(X,Y, zdiff, [0 0]);
% Extract the x- and y-locations from the contour matrix C.
xL = C(1, 2:end);
yL = C(2, 2:end);
% Interpolate on the first surface to find z-locations for the intersection
% line.
zL = interp2(X, Y,Z1, xL, yL);
% Visualize the line.
line(xL, yL, zL, 'Color', 'k', 'LineWidth', 3);
xlabel('X')
ylabel('Y')
zlabel('Z')
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!