Clear Filters
Clear Filters

how to plot two nonlinear functions

3 views (last 30 days)
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

Accepted Answer

Sam Chak
Sam Chak on 31 Aug 2024
Edited: Sam Chak on 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 Comments
Muhammad Asad
Muhammad Asad on 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 on 31 Aug 2024
Hi @Muhammad Asad, You can follow @Torsten's solution to plot the intersection between two surfaces.

Sign in to comment.

More Answers (2)

Torsten
Torsten on 31 Aug 2024
Edited: Torsten on 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')

Muhammad Asad
Muhammad Asad on 1 Sep 2024
Thanks @Torsten and @Sam Chak

Products

Community Treasure Hunt

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

Start Hunting!