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

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

回答(1 个)

Prateekshya
Prateekshya 2024-10-4
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!

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by