How to Use the Contourf Function in MATLAB for a Physics Exercise?

  • Thread starter Chado
  • Start date
  • Tags
    Error
In summary, to create a program to picture the field on the space, you will need to define the x and y coordinates of the data points, calculate the values of the field at each point using the expression for a dipole in a random spot, and then input all three matrices into the contourf function to generate a graph. You may encounter errors when trying to input the matrices and generate the graph, so it is important to carefully check your code for any mistakes and make any necessary corrections.
  • #1
Chado
1
0
Hey, everyone. I need to finish this project and it would be a great help if there was some help. The problem is I have no experience with countourf function of MATLAB but I was asked to transform a physics exercise to it.

In the spoilers there will be all of the problem solved.

Also once I get there I will way what were my problems as I tried to type it in matlab.

1) What's the general expression of a dipole in a random spot? (I will give this further on)
2) Create a program (or an mfile) that will picture the field on the space.
The above means to unite all the points that equal with contourf, in a faction that two circles will be created and will show the field.



We were told to use in the pc :

y=[ -5*d : d/1000 : 5*d]
x=[ -5*d : d/1000 : 5*d]
z= [i,j] which is = Eg and that the i and j will behave like I=0 , i=i+1 and j=j+1

and all the above will be put in the contourf.

If you open the open office file (it's in .doc for the Word users) I used the Math to give the huge funcion.
I tried to break it down in pieces and the do build it but again

here is one of those :

E1=((x-d/2)/(((x-(d/2)).^2).^(3/2)))- ((x+d/2)/((((x+(d/2)).^2)+y^2).^(3/2)))

But MATLAB give me back :

? Error using ==> mpower
Matrix must be square.

You might ask:
What are you asking ?
1) what's i the mistake I did and the error pops up?
2) How will I use the contourf to give me result i want ?

Thanks in Advance.

(Note: I will edit the graph if needed and the previous parts of the final function, just in case i did a mistake.)
 

Attachments

  • Χωρίς τίτλο 1.doc
    25 KB · Views: 220
Physics news on Phys.org
  • #2
The general expression for a dipole in a random spot is:E = (1/4πε₀) ((p•r̂)/(r³))where p is the dipole moment, ε₀ is the permittivity of free space, r̂ is the unit vector pointing from the dipole to the point at which the field is being evaluated and r is the distance between the dipole and the point.To create a program to picture the field on the space, you can use the MATLAB function contourf. The basic syntax of this function is contourf(x,y,z), where x and y are matrices defining the x- and y-coordinates of the data points, and z is a matrix defining the values of the field at each of those points. In your case, you would need to first define the x and y coordinates of the data points as y=[ -5*d : d/1000 : 5*d] and x=[ -5*d : d/1000 : 5*d], and then define the values of the field at those points using the expression for a dipole in a random spot given above. To do this, you would need to define a matrix z such that z=Eg, where Eg is the value of the field at each point for the given dipole. Since you have not specified the values of the dipole moment, the unit vector, or the distance between the dipole and the point, you will need to define these variables accordingly. Once you have defined the x and y coordinates, the dipole moment, the unit vector, and the distance between the dipole and the point, you can then evaluate the matrix z by looping through each element of the matrices x and y and calculating the value of the field at that point. Once you have calculated the values of the field, you can then input all three matrices into the contourf function and generate a graph of the field.
 

Related to How to Use the Contourf Function in MATLAB for a Physics Exercise?

1. What is Contourf and how is it used in scientific research?

Contourf is a function in MATLAB that creates a filled contour plot. This type of plot is commonly used in scientific research to visualize and analyze data in 2D or 3D. It is particularly useful for representing data that varies continuously over a defined area or domain.

2. How does Contourf handle missing or incomplete data?

Contourf has a built-in feature that allows for missing or incomplete data to be handled in a customizable way. By default, it assigns a value of NaN (Not a Number) to missing data points, but this can be changed using the 'MissingDataColor' property.

3. What is the purpose of the 'Error' function in relation to Contourf?

The 'Error' function in MATLAB is used to calculate error or uncertainty in data. It can be used in conjunction with Contourf to visualize the uncertainty of the data being plotted. This can be helpful in understanding the reliability of the data and identifying areas where further investigation may be needed.

4. What is the 'mpower' function and how is it used in scientific research?

The 'mpower' function in MATLAB is used to raise a matrix to a power. This can be useful in scientific research for performing operations on matrices, such as finding eigenvalues and eigenvectors, solving systems of equations, and performing transformations on data.

5. Can the 'mpower' function be used with non-square matrices?

No, the 'mpower' function can only be used with square matrices. If a non-square matrix is given as input, MATLAB will return an error. To perform matrix operations on non-square matrices, the 'mtimes' function can be used instead.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
Back
Top