Extract a function from a table
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 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
il 17 Nov 2019
Walter Roberson
il 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
il 17 Nov 2019
Walter Roberson
il 17 Nov 2019
Is it possible that you have a variable named diff?
Sarah CHOUCHENE
il 18 Nov 2019
Walter Roberson
il 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
il 20 Nov 2019
Walter Roberson
il 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
il 20 Nov 2019
Modificato: Sarah CHOUCHENE
il 20 Nov 2019
Sarah CHOUCHENE
il 20 Nov 2019
Sarah CHOUCHENE
il 20 Nov 2019
Walter Roberson
il 20 Nov 2019
What did the problem turn out to be?
Sarah CHOUCHENE
il 20 Nov 2019
Risposte (0)
Categorie
Scopri di più su Mathematics and Optimization in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!