On Thursday, August 13, 2015 at 7:16:58 AM UTC-4, William Unruh wrote:
I am solving a set of ODEs with dsolve,numeric, and would like to fit a straight line to a portion of the output. I have no idea how I would do
that. Ex, lets assume I have an equation
diff(y(x),x)=5*I*y(x) +3
y(0)=3
and I want to fit a straight line to the output between x=70 to x=90
(I know I can do this analytically but my actual problem is rather more complex
than this.)
You can generate the x and y data and fit a line to that. You can generate the data using a procedure output from dsolve, or you can ask dsolve to return just such an Array of data.
restart:
deq := diff(y(x),x) = .1*y(x) + 3:
IC := y(0) = 3:
sol := dsolve({deq,IC},numeric,output=listprocedure):
Y := eval(y(x),sol):
xdata := [seq(80..90,.5)]:
ydata := map(Y,xdata):
lineseg := CurveFitting:-LeastSquares(xdata,ydata,x,curve=a*x+b):
plots:-display( plot(Y, 80..90),
plot(lineseg, x=80..90,color=blue) );
Alternatively you could get dsolve itself to return the data (as a Matrix with x and y data in its two columns).
res := dsolve({deq,IC},numeric,output=Array(xdata)):
lineseg := CurveFitting:-LeastSquares(res[2][1],x,curve=a*x+b);
Hope I understood your goal properly. If instead you just wanted a line segment to be drawn between y(80) and y(90) then you can use the Y above and plottools:-line([80,Y(80)], [90,Y(90)]) .
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)