MATLAB Script Help - Plotting 2 Functions to Find Intersection

  • MATLAB
  • Thread starter MMCS
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses a short MATLAB script that uses iteration to plot two sets of functions and find their intersection. However, due to the lack of variables and the use of constants, the incorrect graph only shows points instead of the two functions. The suggestion to vary the variable w or plot m-tanh(m) and use fzero() to find the intersection is also mentioned.
  • #1
MMCS
151
0
Attahced is my short MATLAB script, I am basically trying to use iteration to plot 2 sets of 2 functions to see where they intersect, all other information in the script are constants. attached also is the incorrect graph that i get

flux = F

If = Ifield

Any help would be appreciated
 

Attachments

  • matlab.jpg
    matlab.jpg
    19.1 KB · Views: 472
Physics news on Phys.org
  • #2
You plotted a few points instead of each function.

The way you've defined everything, there are no variables. Everything is a constant, which is why you only get points. Should you be varying w to plot each function?

Also, if you just want to know where the two functions of the form m = tanh(m) intersect, you can also plot m-tanh(m) and use fzero() to find the zero where they are equal.
 

1. How do I plot two functions in MATLAB to find their intersection?

To plot two functions in MATLAB, you can use the "plot" function and specify both functions in the same command. For example: "plot(x, y1, x, y2)" where x is the range of values and y1 and y2 are the two functions. This will create a plot with both functions and you can visually find their intersection.

2. Can I find the exact coordinates of the intersection point using MATLAB?

Yes, you can use the "fzero" function in MATLAB to find the intersection point of two functions. This function takes in the two functions and an initial guess for the intersection point and returns the exact coordinates of the intersection point.

3. How can I change the color or style of the plotted functions?

You can use the "plot" function with additional arguments to specify the color, line style, and marker style of the plotted functions. For example: "plot(x, y1, 'r-', x, y2, 'b--')" will plot the first function in red with a solid line and the second function in blue with a dashed line.

4. Is it possible to label the axes and add a title to the plot?

Yes, you can use the "xlabel", "ylabel", and "title" functions to add labels and a title to your plot. These functions take in a string as an argument to specify the label or title. For example: "xlabel('x values')" will label the x-axis with the specified string.

5. Can I save the plot as an image file for later use?

Yes, you can use the "saveas" function in MATLAB to save your plot as an image file. This function takes in the plot and the desired file name as arguments. For example: "saveas(gcf, 'myplot.png')" will save the current plot as a PNG image with the file name "myplot".

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top