Extract a function from a table
이전 댓글 표시
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
Walter Roberson
2019년 11월 17일
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
2019년 11월 17일
Walter Roberson
2019년 11월 17일
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
2019년 11월 17일
Walter Roberson
2019년 11월 17일
Is it possible that you have a variable named diff?
Sarah CHOUCHENE
2019년 11월 18일
Walter Roberson
2019년 11월 18일
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
2019년 11월 20일
Walter Roberson
2019년 11월 20일
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
2019년 11월 20일
편집: Sarah CHOUCHENE
2019년 11월 20일
Sarah CHOUCHENE
2019년 11월 20일
Sarah CHOUCHENE
2019년 11월 20일
Walter Roberson
2019년 11월 20일
What did the problem turn out to be?
Sarah CHOUCHENE
2019년 11월 20일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!