Message Boards Message Boards

GROUPS:

Use NDSolve to calculate a particular x-value, given y-value?

Posted 4 months ago
789 Views
|
2 Replies
|
1 Total Likes
|

Hello,

I am trying to use the interpolating function generated by NDSolve to calculate the time at which the function reaches a value of 1. I tried the following code:

q = 3/100
c = 1/2
b = d = 1
k = G = 20000
g = 1
slv = NDSolve[{x'[t] == x[t]*b*h[t]/G - x[t]*d*x[t]/k, 
   y'[t] == 
    y[t]*b*(1 - c*g)*h[t]/G + y[t]*b*(1 - c*g)*g*(1 - h[t]/G) - 
     y[t]*d*(x[t])/k, h'[t] == -q*h[t], x[0] == k, y[0] == 1, 
   h[0] == G}, {x, y, h}, {t, 0, 1000}]

FindRoot[x[t] /. slv == 1, {t, 0}]

But receive the following error:

FindRoot::nlnum: The function value {-1.+x[0.]} is not a list of numbers with dimensions {1} at {t} = {0.}.

Any help would be greatly appreciated!

Thank you,

Alex

Attachments:
POSTED BY: Alex L
Answer
2 Replies
Posted 4 months ago

The first thing I did was modify your code slightly so I could take a look at the graph and see where the root might be.

q=3/100;c=1/2;b=d=1;k=G=20000;g=1;
slv=x[t]/.NDSolve[{x'[t]==x[t]*b*h[t]/G-x[t]*d*x[t]/k,
y'[t]==y[t]*b*(1-c*g)*h[t]/G+y[t]*b*(1-c*g)*g*(1-h[t]/G)-
y[t]*d*(x[t])/k,h'[t]==-q*h[t],x[0]==k,y[0]==1,
h[0]==G},{x[t],y[t],h[t]},{t,0,1000}][[1]];
Plot[slv,{t,100,1000}]

That shows me that x[t] will not equal 1 anywhere in the range of 0..1000. Outside that range it is going to have to extrapolate and any result will be far more questionable. Does this give you any idea where to begin looking for the reasons this has happened?

Note, to be really honest, the first plot I did included x[t],y[t] and h[t] from 0..1000. You might peek at that graph.

Posted 4 months ago

Thank you!! I see what I was doing wrong now.

POSTED BY: Alex L
Answer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract