# Mathematica: 2nd order PDE, variable coefficients

1. Oct 3, 2010

### hasidim

$$a\text{''}[t]+B[t]*a'[t]-A[t]*a[t]==0$$

a[0] = 10^-9
a'[0] = 0
a[t] = ?

The coefficients A and B are variable over time. I HAVE solved (experimental and theoretical values) for the values of A and B over the time interval of interest!

I attempted to solve for a[t] using NDSolve as one normally would when coefficients are not variable over time. No luck.

Any help would be greatly appreciated!

2. Oct 4, 2010

3. Oct 4, 2010

### phyzguy

I agree that NDSolve should work for this. Just for the record, this is an ODE, not a PDE.

4. Oct 4, 2010

### hasidim

Oh geez, yeah, I meant ODE... it was a little late at night.

So, here is code. SolutionA, SolutionB and SolutionC are for R(t), R'(t), and R''(t).

For coefficients A and B:
$$A[\text{t\_}] = \text{constants}*\frac{R\text{''}[t]}{R[t]}-\frac{\text{constants}}{\rho *(R[t])^3}+\frac{R'[t]}{(R[t])^3}*\left(\text{constants}*\frac{1}{1+2*\psi /R[t]}\right);$$
$$\text{AA}= \text{Evaluate}[A[t]\text{/.}\text{SolutionA}\text{/.}\text{SolutionB}\text{/.}\text{SolutionC}]$$

$$B[\text{t\_}] =3 \frac{R'[t]}{R[t]}+\frac{\text{constants}}{(R[t])^2}*\left(\frac{\text{constants}}{\text{constants}*R[t]}\right);$$
$$BB = Evaluate[B[t] /. SolutionA /. SolutionB /. SolutionC];$$

Attempt at using NDSolve (for SolutionD):

$$SolutionD = NDSolve[{a''[t] + BB*a'[t] - AA*a[t] == 0, a[0] == 10^-9, a'[0] == 0}, a[t], {t, 0, tmax}];$$

I've tried making AA and BB into tables, I've tried using DSolve, and so on.

Thanks a million for the help.

Last edited: Oct 4, 2010
5. Oct 4, 2010

### Simon_Tyler

Although that's a lot of detail (and it's probably best to use a code block, rather than latex) it's still hard to tell what could be causing the problem.
One small thing (which is probably a problem with you're copy/pasting) is that the you should bracket {t,0,tmax}.
Can you:
1) Supply the error message that NDSolve is giving
2) Give the form of Solution* (and are \psi and \rho numerical?)
3) Provide a copy of the notebook (preferably with any extraneous stuff removed)

I'm guessing that R[t] must be some numerical/interpolated function. Here's a simple example showing the use of an interpolated function and NDSolve. Note that the interpolation becomes bad at around x=4.
Code (Text):
data=Table[{x,Cos[Exp[x]]},{x,0,5,.05}];
AA=Interpolation[data];
Code (Text):
Plot[{Cos[Exp[x]],AA[x]},{x,0,5}]
Code (Text):
sol1=NDSolve[{y'[x]+Cos[Exp[x]] y[x]==0,y[0]==1},y,{x,0,5}];
sol2=NDSolve[{y'[x]+AA[x] y[x]==0,y[0]==1},y,{x,0,5}];
Code (Text):
Plot[Evaluate[Flatten[y[x]/.{sol1,sol2}]],{x,0,5}]

6. Oct 4, 2010

### suhan786

This is very difficult to me, because i am a new user here.
==================================
http://www.bestbankrates.net" [Broken]

Last edited by a moderator: May 5, 2017
7. Oct 4, 2010

### hasidim

phyzguy and Simon_Tyler, thanks for the help.

I found the issue: it wasn't with my finding a[t] directly, it was solving for R[t], R'[t], and R''[t] (I wasn't getting real values). Also, I was reaching my maximum number of steps when using NDSolve to find a[t].

Also, I am still new and learning (mathematica and forums), I didn't realize there was a code block, so for what it is worth, this worked beautifully:

Code (Text):
SolutionD =
NDSolve[{a''[t] + BB*a'[t] - AA*a[t] == 0, a[0] == 10^-9,
a'[0] == 0}, a[t], {t, 0, tmax}, MaxSteps -> 700000000];

CC = Evaluate[a[t] /. SolutionD];

8. Oct 5, 2010