Borrar filtros
Borrar filtros

How can I plot a plane in a 3D space by using symbolic functions?

5 visualizaciones (últimos 30 días)
Moein
Moein el 30 de Sept. de 2014
Respondida: Prateekshya el 4 de Oct. de 2024 a las 10:51
i have a 3D function like T(x,y,z) that is symbolic. then i should use ezfunctions to plot it. i want to define a plane in the 3D domain of my function to display the rates of my function on it. i'm new to matlab if you want to answer my question please explain. an example image that i want to create like that, is available in attached files
thanks

Respuestas (1)

Prateekshya
Prateekshya el 4 de Oct. de 2024 a las 10:51
Hello Moein,
To visualize a symbolic 3D function in MATLAB and plot its values on a defined plane, you can use symbolic math and plotting functions. While the ezplot functions (like ezsurf) are convenient for quick plots, they are somewhat limited. Here is a workaround for your requirement:
  • Define the Symbolic Function: First, define your symbolic function using syms and symbolic expressions.
syms x y z
T = x^2 + y^2 - z^2; % Example symbolic function
  • Visualize the Function in 3D: Use fsurf to visualize the function. You need to express z in terms of x and y if you want to plot a surface.
% Solve for z in terms of x and y (assuming T(x, y, z) = 0 for simplicity)
z_expr = solve(T == 0, z);
% Convert the symbolic expression to a MATLAB function handle
z_func = matlabFunction(z_expr);
% Plot the surface
fsurf(z_func, [-5, 5, -5, 5]) % Adjust the range as needed
xlabel('x')
ylabel('y')
zlabel('z')
title('Surface of T(x, y, z) = 0')
  • Define and Plot a Plane: If you want to plot the values of T on a specific plane, define the plane equation. For example, a plane z = constant or y = constant.
% Define a plane, e.g., z = 2
z_plane = 2;
[X, Y] = meshgrid(-5:0.5:5, -5:0.5:5); % Adjust range and resolution
Z = z_plane * ones(size(X));
% Evaluate T on the plane
T_values = double(subs(T, {x, y, z}, {X, Y, Z}));
% Plot the plane with T values
hold on
surf(X, Y, Z, T_values, 'EdgeColor', 'none')
colorbar
title('T(x, y, z) on Plane z = 2')
  • Adjust Plot Settings: Use axis to adjust the axis limits if necessary. Use colormap to change the color scheme of the plot. Add labels and a title to clarify the plot.
I hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by