how to plot two nonlinear functions

2 次查看(过去 30 天)
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

采纳的回答

Sam Chak
Sam Chak 2024-8-31
编辑:Sam Chak 2024-8-31
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 个评论
Muhammad Asad
Muhammad Asad 2024-8-31
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 2024-8-31
Hi @Muhammad Asad, You can follow @Torsten's solution to plot the intersection between two surfaces.

请先登录,再进行评论。

更多回答(2 个)

Torsten
Torsten 2024-8-31
编辑:Torsten 2024-8-31
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')

Muhammad Asad
Muhammad Asad 2024-9-1
Thanks @Torsten and @Sam Chak

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by