Message Boards Message Boards

1
|
6109 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to plot a function depending on an Interpolating function ?

Hello,

I have plot a function B[t], solved from a differential equation. It gave me an interpolating function B: { {B => InterpolatingFunction [ {{0,.60}}, <> ] }} I would like now to plot another function depending on B, that would be: (A2*B + A1 - rho) / eta, with rho (=0.96 for exemple) and eta (=2 for exemple) two constant parameters, and A1 and A2 defined below. But I can't manage to plot this function depending on the interpolating function. If someone knows how to do it, it would be great help !

Here is the equation that permitted me to find the trajectory of B:

A1 = \[Theta]1*B[t] + \[Theta]2
A2 = \[Theta]1
\[Theta]1 = 0.03
\[Theta]2 = 0.04

\[Alpha] = 0.32
\[Delta] = 0.1
\[Gamma] = 0.5
p = 1
s = NDSolve[{\[Alpha] *(1/(\[Alpha] - 1) ((A1*B[t] + A2 + \[Delta])/\[Alpha])^(1/(\[Alpha] - 1) -1)*((A1*B'[t])/ \[Alpha]) )/((1 - \[Alpha]) ((A1*B[t] + A2 + \[Delta])/\[Alpha])^(\[Alpha]/(\[Alpha] -1)) + \[Gamma]*p)   == A1*B[t] + A2 , B[0] == 50},  B, {t, 0, 60}]
POSTED BY: Emma Hooper
4 Replies
Posted 10 years ago

Alexey wrote solution where is used values from interpolation coefficient (polynomial). Solved values have small error. If you want solve other t-values and use interpolation function for solution then you can write this code:

tab = Table[{t, B[t] /. s[[1]]}, {t, 0, 21, 0.1}];
TableForm[tab]

For exporting data to XLS format you can use:

file = SystemDialogInput["FileSave", "data.xls", 
   WindowTitle -> "Select a XLS to Save "];
Export[file, 
 Join[{{"t", "B[t]"}}, tab]] (*added head*)
POSTED BY: Mirek M
Posted 10 years ago

Hello,

you can append this code:

sNew[time_] := (A2*B[t] + A1 - rho)/eta /. {rho -> 0.96, eta -> 2} /. 
   s[[1]] /. t -> time;
Plot[{B[k] /. s, sNew[k]}, {k, 0, 5}]

or

Plot[{B[t] /. 
   s, (A2*B[t] + A1 - rho)/eta /. {rho -> 0.96, eta -> 2} /. 
   s[[1]]}, {t, 0, 5}]

Good feature is replace endTime=5 for

endTime = s[[1, 1, 2, 1, 1, 2]];

because you set real solved time.

M. M.

POSTED BY: Mirek M

Great ! Tanks a lot, it worked :)

Do you know how I can recover the data of the numerical values of B, in order to have a table with the values of B ?

B is still the interpolating function, solved from the differential equation above...

POSTED BY: Emma Hooper
Posted 10 years ago
if = B /. s[[1]];
intPoints = Transpose[{Flatten@#["Grid"], #["ValuesOnGrid"]}] &[if];
TableForm[intPoints]
POSTED BY: Alexey Popkov
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