Extract a function from a table
Show older comments
Hello,
I really need to clear up my toughts, I want to extract a fonction from a table of two dimensions ( l,t) that I recover from and ODE method.
[t,l]=ode23('odef',[t0,tf],l0)
My goal is to integrate "l" Si I need to have a function to use for exemple the simpson method :
f = inline('l','t')
h = 100/N;
Isim=0.0;
for i=1:N
Isim= Isim+h*(1/6*f(t(i))+2/3*f((t(i)+t(i+1))/2)+1/6*f(t(i+1)));
end
Isim
Of corse this program doesn't work because I used a vecto as a function !
Do you have an idea how can I integrate from data ?
Thank you,
Regards,
14 Comments
Walter Roberson
on 17 Nov 2019
Do a substitution of functions l = dL and solve for L.
In other words just add one more state variable that is fed from the current variable, and the output for that new variable will automatically be the numeric integration.
Sarah CHOUCHENE
on 17 Nov 2019
Walter Roberson
on 17 Nov 2019
For example if you had
function dx = odef(t, x)
dx(1,1) = 2*x-sin(x(1));
Then you would change to
function dx = odef(t, x)
dx(1,1) = 2*x-sin(x(1));
dx(2,1) = x(1);
And now the second column of output would be the numeric integration of the first column.
Sarah CHOUCHENE
on 17 Nov 2019
Walter Roberson
on 17 Nov 2019
Is it possible that you have a variable named diff?
Sarah CHOUCHENE
on 18 Nov 2019
Walter Roberson
on 18 Nov 2019
You indicate that on the line
int=diff(fnval(fnint(ys),[0 4]))
you are getting an error about array indices. You should check
which fnint
which fnval
which diff
to see if any of them are variables instead of functions at that point in your code.
Sarah CHOUCHENE
on 20 Nov 2019
Walter Roberson
on 20 Nov 2019
Try this series of steps and see which one reports the subscript error:
temp1 = fnint(ys);
temp2 = [0 4];
temp3 = fnval(temp1, temp2);
int = diff(temp3);
Sarah CHOUCHENE
on 20 Nov 2019
Edited: Sarah CHOUCHENE
on 20 Nov 2019
Sarah CHOUCHENE
on 20 Nov 2019
Sarah CHOUCHENE
on 20 Nov 2019
Walter Roberson
on 20 Nov 2019
What did the problem turn out to be?
Sarah CHOUCHENE
on 20 Nov 2019
Answers (0)
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!