- Adjust the ranges for u, p, and z as needed to capture the relevant parts of the plot.
- The "fimplicit3" function is used to plot the implicit equation, while "isosurface" is used to visualize the volume where the inequality is satisfied.
- The "isosurface" function plots the surface where the inequality function is zero, which helps visualize the boundary of the region satisfying the inequality.
Plot 3d implicit function and inequality
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I need to plot a 3d equation and inequality, with some constraints. The equation and inequality are the following
(u.^2).*(p.^2).*(1-exp(-r.*z))-2.*u.*p.*t.*(1+exp(-r.*z))+(t.^2).*(1-exp(-r.*z))+4.*exp(-r.*z)=0
and
(u.^2).*(p.^2).*(1-exp(-r.*z))-2.*u.*p.*t.*(1+exp(-r.*z))+(t.^2).*(1-exp(-r.*z))+4.*exp(-r.*z)<=0
r and t are scalars, say r=0.001 and t=1. u and z can take non-negative values, 0<=u<=1, and 0<=t, while p takes values that either satisfy the equation or inequality. In the case of the equality, I would like to have a 3d plot with u and z in the "lower" axis and p in the "vertical" axis. The same for the inequality though in this case I would need to represent the whole area that satisfies the inequality.
Thanks
0 comentarios
Respuestas (1)
Sanchari
el 23 de Jul. de 2024
Hello Fernando,
To plot the 3D equation and inequality in MATLAB, you can use the "fimplicit3" function for the equation and the "isosurface" function for the inequality. Below is a step-by-step guide to achieve this.
Step 1: define the equation and inequality as anonymous functions.
r = 0.001;
t = 1;
eqn = @(u, p, z) (u.^2).*(p.^2).*(1-exp(-r.*z))-2.*u.*p.*t.*(1+exp(-r.*z))+(t.^2).*(1-exp(-r.*z))+4.*exp(-r.*z);
ineq = @(u, p, z) (u.^2).*(p.^2).*(1-exp(-r.*z))-2.*u.*p.*t.*(1+exp(-r.*z))+(t.^2).*(1-exp(-r.*z))+4.*exp(-r.*z);
Step 2: To plot the equation, use fimplicit3 which plots the implicit function in 3D.
% Define the range for u, p, and z
u_range = linspace(0, 1, 100);
z_range = linspace(0, 10, 100); % Adjust range for z as needed
p_range = linspace(-10, 10, 100); % Adjust range for p as needed
% Plot the equation
figure;
fimplicit3(eqn, [0 1 -10 10 0 10], 'EdgeColor', 'none');
xlabel('u');
ylabel('p');
zlabel('z');
title('3D Plot of the Equation');
grid on;
Step 3: For the inequality, you can use isosurface to plot the volume where the inequality is satisfied.
% Create a grid of points
[u, p, z] = ndgrid(u_range, p_range, z_range);
% Evaluate the inequality on the grid
ineq_values = ineq(u, p, z);
% Plot the inequality using isosurface
figure;
isosurface(u, p, z, ineq_values, 0);
xlabel('u');
ylabel('p');
zlabel('z');
title('3D Plot of the Inequality');
grid on;
Here is the full MATLAB script that combines the above steps:
r = 0.001;
t = 1;
eqn = @(u, p, z) (u.^2).*(p.^2).*(1-exp(-r.*z))-2.*u.*p.*t.*(1+exp(-r.*z))+(t.^2).*(1-exp(-r.*z))+4.*exp(-r.*z);
ineq = @(u, p, z) (u.^2).*(p.^2).*(1-exp(-r.*z))-2.*u.*p.*t.*(1+exp(-r.*z))+(t.^2).*(1-exp(-r.*z))+4.*exp(-r.*z);
% Define the range for u, p, and z
u_range = linspace(0, 1, 100);
z_range = linspace(0, 10, 100); % Adjust range for z as needed
p_range = linspace(-10, 10, 100); % Adjust range for p as needed
% Plot the equation
figure;
fimplicit3(eqn, [0 1 -10 10 0 10], 'EdgeColor', 'none');
xlabel('u');
ylabel('p');
zlabel('z');
title('3D Plot of the Equation');
grid on;
% Create a grid of points
[u, p, z] = ndgrid(u_range, p_range, z_range);
% Evaluate the inequality on the grid
ineq_values = ineq(u, p, z);
% Plot the inequality using isosurface
figure;
isosurface(u, p, z, ineq_values, 0);
xlabel('u');
ylabel('p');
zlabel('z');
title('3D Plot of the Inequality');
grid on;
Pease consider the following:
Hope this helps!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!