how to plot two nonlinear functions

2 ビュー (過去 30 日間)
Muhammad Asad
Muhammad Asad 2024 年 8 月 31 日
回答済み: Muhammad Asad 2024 年 9 月 1 日
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')
  3 件のコメント
Sam Chak
Sam Chak 2024 年 8 月 31 日

サインインしてコメントする。


Muhammad Asad
Muhammad Asad 2024 年 9 月 1 日
Thanks @Torsten and @Sam Chak

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by