Plotting a 3D Gaussian in MATLAB

Click For Summary
SUMMARY

The discussion focuses on plotting a three-dimensional Gaussian function using MATLAB. The equation provided is A = A0 * exp((x^2 + y^2 + z^2)/w^2), where 'w' is a parameter that influences the shape of the Gaussian distribution. Users are guided to utilize the 'surf' command for visualizing a Gaussian distribution of two variables, with a sample code provided: clear; pts = -5:.1:5; N = length(pts); X = reshape(repmat(pts,1,N),N,N); Y = reshape(repmat(pts,N,1),N,N); Z = exp(-X.^2-Y.^2); figure;surf(X,Y,Z). This code effectively generates a surface plot of the Gaussian distribution.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of Gaussian functions and their parameters
  • Knowledge of 3D plotting techniques in MATLAB
  • Basic concepts of matrix manipulation in MATLAB
NEXT STEPS
  • Explore MATLAB's 'surf' function for 3D surface plotting
  • Learn about Gaussian distribution parameters and their effects on shape
  • Investigate how to visualize functions of three variables in MATLAB
  • Study MATLAB's matrix operations for reshaping and replicating data
USEFUL FOR

This discussion is beneficial for students, educators, and researchers in fields such as mathematics, physics, and engineering who are looking to visualize Gaussian distributions in MATLAB.

debwaldy
Messages
34
Reaction score
0

Homework Statement


Hi all! I'm trying to solve the following problem but I'm not too sure of a few things.
Write Matlab instructions to plot a three dimensional Gaussian:

A = A0exp((x^2 + y^2 + z^2)/w^2)

choosing appropriate values for A0,w and range of coordinates.


Homework Equations


I'm guessing i have to use the plot3 command but after that I'm lost


The Attempt at a Solution


I don't know how to choose appropriate values for all of the variables.And what is w?
I'm a bit lost so I'd really appreciate any hints or tips to point me in the right direction thanks debs:smile:
 
Physics news on Phys.org
debwaldy said:

Homework Statement


Hi all! I'm trying to solve the following problem but I'm not too sure of a few things.
Write Matlab instructions to plot a three dimensional Gaussian:

A = A0exp((x^2 + y^2 + z^2)/w^2)

choosing appropriate values for A0,w and range of coordinates.


Homework Equations


I'm guessing i have to use the plot3 command but after that I'm lost


The Attempt at a Solution


I don't know how to choose appropriate values for all of the variables.And what is w?
I'm a bit lost so I'd really appreciate any hints or tips to point me in the right direction thanks debs:smile:

w is a parameter of your Gaussian, make it bigger and the distribution should flatten out.

What exactly do you want to plot? You can't plot A(x,y,z) on a 3D plot because A depends on 3 variables so you would need a 4D plot.

If you want to plot a Gaussian distribution of 2 variables, run the following code in Matlab:
Code:
clear;
pts = -5:.1:5;
N = length(pts);
X = reshape(repmat(pts,1,N),N,N);
Y = reshape(repmat(pts,N,1),N,N);
Z = exp(-X.^2-Y.^2);
figure;surf(X,Y,Z)
Is that the type of plot you are trying to produce?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K