MATLAB MATLAB Script Help - Plotting 2 Functions to Find Intersection

  • Thread starter Thread starter MMCS
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
The discussion centers on a MATLAB script intended to plot two functions and identify their intersection points. The user is experiencing issues with the output graph, which only displays a few points instead of the expected continuous functions. The primary problem identified is that all variables in the script are defined as constants, preventing any variation in the plot. To resolve this, it is suggested to vary the variable 'w' to properly plot each function. Additionally, an alternative approach is recommended: instead of plotting the functions directly, the user can plot the difference between the two functions, m - tanh(m), and utilize the fzero() function to find the intersection point where they are equal.
MMCS
Messages
151
Reaction score
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: 517
Physics news on Phys.org
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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 14 ·
Replies
14
Views
3K
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K