Repeated differential equations

In summary, Andreas tried to solve a system of differential equations in Mathematica by providing initial values, a FOR loop, and solving the equation. However, it appears to be difficult and there is no way to evaluate or plot the results.
  • #1
Andreas_D
4
0
Hi,

I'm trying to make Mathematica calculate a system of differential equations
(initial value problem) in a FOR loop. This looks quite difficult, it seems
impossible to evaluate and plot in a "FOR" loop.

What I try to do is
- give initial parameters
- FOR (...number of repetitions)
- ndsolve differential equation
- return parameters -> new initial parameters
- continue with "FOR" loop

Thank you for any ideas!
Andreas
 
Physics news on Phys.org
  • #2
That is confusing, could you be more specific. In mathematica outpit is supressed inside interation structures like for,while,and do. You can force output using
Print[expr]
 
  • #3
Maybe let's forget about the differential equations for a moment.

It would be helpful to find out how to do a repeated calculation - meaning an iterative one...
I'm used to other languages and I tried something like that - but there is no way in Mathematica:

a_out = 0; # initial value of some parameter
i = 0;
f[x] = x^2 + a_out # some function

For [i<10; i++] # this is how i would write it in C
{
Plot [f[x],{x,0,1}
a_out = f[1] # return calculated value to replace initial parameter
}

so there should be 9 plots of the function f with different parameters a_out. but nothing happens :-(
 
  • #4
Of course there is a way to do that in Mathematica. You just need to learn the syntax correctly.

First, the underscore character is a reserved character used for patterns, so a_out is not a symbol named "a_out", it is a pattern named "a" representing any single object of type "out". Try "aout" instead.

Second, you want to define a function correctly.
f[x] = x^2 + aout
Would immediately evaluate x^2 + aout to get x^2 and would set the symbol f[x] equal to that. This means that changes to aout would have no impact and that f[x] would evaluate to x^2 but f[2] would evaluate to f[2] instead of 4. The correct way to define a function is
f[x_]:= x^2 + aout
or even
f = Function[x, x^2 + aout]

Third, you have the syntax of For completely wrong for Mathematica. Just look up the help entry for For.

Fourth, remember that For evaluates to Null, so you will need to Print[Plot[...]] to get the output you want.
 
  • #5
Hi,

I was quite aware that I'm mixing the languages - in order to find out the mistake in my thinking.
The crucial point was the Print[Plot...] order. Now it works out properly to plot a series of functions with this code:

aout = 0;
For [i = 0, i < 4, i++,
{
f[x_] = x^2 + aout;
Print[Plot[f[x], {x, 0, 1} ]];
aout = f[1]
}
]

Thanks a lot, now I can think about the differential equations :biggrin:
 
  • #6
I'd do something like said above, with parameters X1,X2,X3

SOLN[X1_, X2_, X3_ ] := NDSolve[{system[X1,X2,X3]}]
X1=0;
X2=0;
X3=0;
For [i = 0, i < 4, i++,
{
SOLNF=SOLN[X1,X2,X3];
X1=New something [SOLNF]
X2=New something [SOLNF]
X3=New something [SOLNF]
}
]

that way, the function isn't redefined every loop, but it is reevaluated everytime you call it, with whatever parameters X1,X2,X3 happen to be at the time of the call.
 
  • #7
Thanks, I did that and I think my calculation is faster now... and, in any case, it looks better!
 

Related to Repeated differential equations

What is a repeated differential equation?

A repeated differential equation is a type of ordinary differential equation where the dependent variable appears multiple times in the equation. This means that the equation contains multiple derivatives of the dependent variable with respect to the independent variable.

How do you solve a repeated differential equation?

The process for solving a repeated differential equation involves finding a general solution and then applying initial conditions to determine a particular solution. This can be done using various methods such as separation of variables, substitution, or integrating factors.

What are the applications of repeated differential equations?

Repeated differential equations are commonly used in physics, engineering, and other sciences to model systems that involve repeated rates of change. They can also be used to describe population growth, chemical reactions, and many other phenomena.

What is the difference between a repeated differential equation and a regular differential equation?

The main difference between a repeated differential equation and a regular differential equation is that a repeated differential equation contains multiple derivatives of the dependent variable, while a regular differential equation only contains one derivative. This makes repeated differential equations more complex and often more difficult to solve.

Are there any real-life examples of repeated differential equations?

Yes, there are many real-life examples of repeated differential equations. One example is the damped harmonic oscillator, which is used to model the motion of a mass attached to a spring with damping. Another example is the predator-prey model, which describes the relationship between two species in an ecosystem.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
549
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
690
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • Mechanics
Replies
5
Views
451
  • Calculus and Beyond Homework Help
Replies
7
Views
630
  • MATLAB, Maple, Mathematica, LaTeX
Replies
27
Views
7K
Back
Top