How i can combine two or three 3D plot ? how get the template of such graph?

how i can have template of such graph in below mention it and there is any other template of graph surface? and how i can combine two or more 3D graph in one graph and with one template ? if have a template please share it and plot this kind of graph
(((cosh(0.5e0 * x + 0.20e1 * t) + 0.1e1) / cosh(0.5e0 * x + 0.20e1 * t)) ^ (0.1e1 / 0.6e1)) * exp(i * (-0.2e1 * x - 0.4034722222e1 * t))

3 Comments

I do not understand what you mean by "template" in this circumstance?
@Walter Roberson let me clearify for you something like that, if this is have other name please tell me, i just want put my function on it and do run also i want plot two graph in on plot do you have any template now?

Sign in to comment.

Answers (1)

Hi @salim saeed,

First define the range for the variables x and t using linspace, which generates linearly spaced vectors. The meshgrid function is then used to create a grid of X and T values. The core mathematical expression is defined in the variable Z. This expression involves hyperbolic cosine functions and an exponential term, which is computed over the grid defined by X and T. The, use surf function to create a 3D surface plot of the real part of Z. The plot will be enhanced with titles and labels for clarity, and a color bar is added to indicate the scale of values. To combine multiple 3D graphs, use the hold on command, which allows us to overlay additional plots on the same figure. A second mathematical expression Z2 is defined and plotted with a specified transparency using the FaceAlpha property. This will help in visualizing both surfaces simultaneously without obscuring one another. Finally, a legend is added to distinguish between the two expressions, and the hold off command is used to finalize the plotting.

% Define the range for x and t
x = linspace(-10, 10, 100);
t = linspace(-10, 10, 100);
[X, T] = meshgrid(x, t);
% Define the mathematical expression
Z = ((cosh(0.5 * X + 20 * T) + 1) ./ cosh(0.5 * X + 20 * T)).^(1 / 6) .* exp(1i   * (-2 * X - 40.34722222 * T));
% Plot the real part of Z
figure;
surf(X, T, real(Z));
title('3D Surface Plot of the Given Expression');
xlabel('X-axis');
ylabel('T-axis');
zlabel('Real Part of Z');
colorbar;
grid on;
% Combine multiple 3D graphs
hold on;
% Define another mathematical expression for demonstration
Z2 = ((cosh(0.3 * X + 15 * T) + 1) ./ cosh(0.3 * X + 15 * T)).^(1 / 6) .* 
exp(1i * (-1.5 * X - 30 * T));
% Plot the real part of the second expression
surf(X, T, real(Z2), 'FaceAlpha', 0.5); % Set transparency for better 
visualization
% Add legend and title
legend('Expression 1', 'Expression 2');
title('Combined 3D Surface Plots');
hold off;

Please see attached.

Please let me know if you have any further questions.

5 Comments

Thank you for your emazing writing code, of curse i have a lot of question in my mind, my code is so different from yours i do my setteing up all prameter in maple after that i just transfer it to matlab and matlab give me what i want with a good high graphic at there i just use this code
fs=fsurf(@(x,t)real(0.4690415759e1 * sinh(0.50e1 * x + 0.4035799242e1 * t) ./ cosh(0.50e1 * x + 0.4035799242e1 * t) .* exp(i * (0.3122880506e1 * t - 0.50e1 * x))),'ShowContours','on');
this is the first step of template, it give me realy a good graphic, first problem in your template when i change the function give me error
secondly i don't want combine two function the same they must different like abs(z).^2 and real(z) or imag(z) this kind of graph have a tamplate which is so different from yours my means about graphic i want get them but i don't know how also four countor graph we have a different shape of template for effect of time too for effect desity and i am looking for other kind graph too

Hi @salim saeed ,

To address your query effectively, let me break down your concerns into manageable components:

Modifying the Function in Your Template

When you change the function within your fsurf command, it’s essential to ensure that the new function is compatible with the input parameters x and t. If you encounter errors, these could stem from syntax issues or from the new function not being defined properly over the specified domain. Here’s an example of how to set up a different function while maintaining your original structure:

fs = fsurf(@(x,t) abs(0.5 * exp(i * (x + t))), 'ShowContours', 'on');

Make sure that any functions you use return valid outputs for all combinations of x and t over the defined ranges.

Creating Distinct Graphical Representations

For generating graphs that depict different aspects of complex functions (like abs(z).^2, real(z), or imag(z)), you can create separate plots using MATLAB's plotting functions. Here’s how you might plot these different representations:

   % Define a complex function
   z = @(x,t) 0.4690415759e1 * sinh(0.50e1 * x + 0.4035799242e1 * 
   t) ./ cosh(0.50e1 * x + 0.4035799242e1 * t) .* exp(i *    (0.3122880506e1 * t - 0.50e1 * x));
   % Plot absolute square
   figure;
   fsurf(@(x,t) abs(z(x,t)).^2, 'ShowContours', 'on');
   title('Absolute Square');
   % Plot real part
   figure;
   fsurf(@(x,t) real(z(x,t)), 'ShowContours', 'on');
   title('Real Part');
   % Plot imaginary part
   figure;
   fsurf(@(x,t) imag(z(x,t)), 'ShowContours', 'on');
   title('Imaginary Part');

Contour Graphs and Time Effects To create contour graphs that reflect changes over time and density, you might consider using MATLAB's contour or contourf functions alongside your existing surfaces. For example:

   [X, T] = meshgrid(-5:0.1:5, -5:0.1:5); % Create a grid for x and
   t
   Z = z(X,T); % Compute values
   figure;
   contour(X, T, abs(Z).^2); % Contour plot for absolute square
   title('Contour of Absolute Square over Time and Density');
   xlabel('X-axis');
   ylabel('T-axis');

MATLAB supports various types of visualizations such as surface plots (surf), mesh plots (mesh), and polar plots (polarplot). Depending on your data's nature, these might provide different insights.

If you have further questions or need assistance with specific aspects, feel free to ask!

thank you @Umar i will work on it a little bit i have a lot question but i need practice more to clerify undrestand the code , and one more question how we can add a small part of two dimention or even contour graph to 3D plot both apear in one graph contour as mention in the graph of post by position do can do that? and there is any way for contact you individually ?

Hi @salim saeed,

To achieve the desired effect of displaying both a 3D surface plot and a 2D contour plot in MATLAB, you can use the surf function for the 3D surface and the contour or contourf function for the 2D representation. Here is a step-by-step guide:

Define Your Functions: First, ensure you have your function defined for both the surface and contour plots. For example, let’s say we have a function (z = f(x, t) ).

   % Define the function
   z = @(x, t) sin(sqrt(x.^2 + t.^2)); % Example function

Create a Meshgrid: Use meshgrid to create matrices for your x and t values over which you will evaluate your function.

   [X, T] = meshgrid(-5:0.1:5, -5:0.1:5); % Create grid for x and t
   Z = z(X, T); % Compute Z values

Plot the 3D Surface: Use the surf function to create your 3D plot.

   figure;
   surf(X, T, Z); % Create surface plot
   hold on; % Retain current plot when adding new plots

Overlay the Contour Plot: Use the contour3 function to add contours on top of your surface plot. The contour3 function creates contour lines in 3D space.

   contour3(X, T, Z, 20, 'k'); % Overlay contour lines (20 levels)
   hold off; % Release current plot hold

For more information on contour3 function, please refer to

https://www.mathworks.com/help/matlab/ref/contour3.html

Enhance Visualization: You may want to add labels and titles to make your graph more informative.

   title('3D Surface with Contours');
   xlabel('X-axis');
   ylabel('T-axis');
   zlabel('Z-axis');

You can customize the number of contour levels by changing the number in contour3(X, T, Z, N) where N is the number of levels you desire. Consider using colormaps (`colormap`) to enhance visual distinction between different levels of contours. MATLAB also allows for interactive features such as rotating the plot (`view`) and zooming in on specific areas to better analyze data.

By following these steps, you can effectively overlay a contour plot on top of a 3D surface plot in MATLAB, allowing for an enriched visualization that conveys more information about their data.

Note: We are not allowed to share personal information at Mathworks forum. If you have any questions, please post them on the forum, we will be happy to help you out.

If there are further questions or if additional clarification is needed on specific aspects of this process, please feel free to ask!

@Umar thank you so much you did a great help for me i owe you , you didn't answer my question about how contact you individually? this is my email it is my pleasure if you send me some good mathworks forum and it is not a share is just like a help (salmsaedmahmod@gmail.com).
Thanks.

Sign in to comment.

Products

Release

R2023b

Asked:

on 5 Oct 2024

Commented:

on 6 Oct 2024

Community Treasure Hunt

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

Start Hunting!