how to plot two nonlinear functions

1 Ansicht (letzte 30 Tage)
Muhammad Asad
Muhammad Asad am 31 Aug. 2024
Beantwortet: Muhammad Asad am 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

Akzeptierte Antwort

Sam Chak
Sam Chak am 31 Aug. 2024
Bearbeitet: Sam Chak am 31 Aug. 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 Kommentare
Muhammad Asad
Muhammad Asad am 31 Aug. 2024
Thanks Sam Chak. i am expecting like below, which i drew one by one by fimplicit and hold on. but i want to draw them togather. Thanks
Sam Chak
Sam Chak am 31 Aug. 2024
Hi @Muhammad Asad, You can follow @Torsten's solution to plot the intersection between two surfaces.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Torsten
Torsten am 31 Aug. 2024
Bearbeitet: Torsten am 31 Aug. 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')
  3 Kommentare
Sam Chak
Sam Chak am 31 Aug. 2024

Melden Sie sich an, um zu kommentieren.


Muhammad Asad
Muhammad Asad am 1 Sep. 2024
Thanks @Torsten and @Sam Chak

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by