Mathematica help needed, please (very simple?)

  • Mathematica
  • Thread starter *best&sweetest*
  • Start date
  • Tags
    Mathematica
In summary, the conversation discussed the need to construct a direction field plot for a differential equation using Mathematica. The code for the plot was provided, as well as a question about adjusting the plot to show more detail in a specific range. Suggestions were given for adjusting the plot, including using the HeadWidth option and creating a customized plot using the Arrow package.
  • #1
*best&sweetest*
36
0
I need to construct a direction field plot for a differential equation and I have this code

Needs["Graphics`PlotField`"];
PlotDirectionField[ff_, {x_, a_, b_}, {y_, c_, d_}] := Module[{f}, f = \
Compile[{x, y}, ff]; PlotVectorField[{190, f[x, y]}, {x, a, b}, {y, c,
d}, ScaleFunction -> (1 &), Axes -> True, Ticks -> None, Frame -> True,
AspectRatio -> 1] ];

and after that I plot the field entering the following code
PlotDirectionField[f[x,y], {x,a,b}, {y,c,d}]
where f[x,y] is the right hand side of my equation.

My problem is that I need to show field for x in quite big interval (from 0 to 30 - a=0,b=30) and I know that the solution curve behaves differently between 0 and 1 than what the field shows. How can I make the plot so that on the x-axis I have intervals of, let's say, 0.1 instead of 1 all the way between 0 and 30?:confused:

Thanks for help!
 
Physics news on Phys.org
  • #2
First of all, I don't understand why you use a module to compile the function. All plot functions in mathematica automatically compile their arguments.

It sounds like you are not getting enough detail in the arrows, that you want there to be more arrows in the region 0 to 1. First try decreasing the HeadWidth option. If this is not sufficient, I see the following choices:

1) Picture within a picture, i.e. you Show a plot from 0 to 1 superimposed on the plot from 0 to 30, so that there is a higher density of arrows from 0 to 1.

2) Using the Arrow package, create your own customized PlotVectorField function that allows the user to input a density function which gives the densities of the arrows.

Sorry I do not know a simpler way! In my experience, the built in PlotVectorField is not very robust.
 
  • #3


Hi there,

Thank you for reaching out for help with Mathematica. It looks like you are trying to plot a direction field for a differential equation using the PlotField package. To change the intervals on the x-axis, you can use the option "ScaleFunction" and specify a function that will scale the intervals. For example, to have intervals of 0.1 on the x-axis, you can use the following code:

PlotDirectionField[f[x,y], {x,0,30}, {y,c,d}, ScaleFunction -> (1/10 &)]

This will scale the intervals on the x-axis by a factor of 1/10, resulting in intervals of 0.1.

I hope this helps. Let me know if you have any further questions.
 

1. What is Mathematica and what is it used for?

Mathematica is a computational software program used for mathematical, scientific, and engineering calculations, data analysis, and visualization. It is commonly used in fields such as physics, chemistry, economics, and engineering.

2. How do I input and manipulate data in Mathematica?

To input data in Mathematica, you can use the input bar or type directly into the notebook. To manipulate data, you can use built-in functions and operators, as well as create custom functions using the Wolfram Language.

3. What resources are available for learning Mathematica?

There are various resources available for learning Mathematica, including tutorials and documentation on the official Wolfram website, online courses, and community forums where users can ask for help and share tips and tricks.

4. How can I troubleshoot errors in Mathematica?

If you encounter errors in Mathematica, you can check the documentation for the function or operation you are using to see if there are any known issues or limitations. You can also try simplifying your code or breaking it down into smaller steps to identify the source of the error.

5. Is Mathematica compatible with other programming languages?

Yes, Mathematica has the ability to import and export data in various formats, including those used in other programming languages such as Python and Java. It can also be integrated with other programming languages through the use of APIs and libraries.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
200
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
155
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
950
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top