이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Extract a function from a table
조회 수: 2 (최근 30일)
이전 댓글 표시
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일
Thank you for your response, I don't really understand what do you mean by dL, is d the derivation ? How can I do this on matlab, because if I put l=dL it doesn't solve my problem...
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일
Hello,
thank you very much for your answer, I tryed it and I have the second column as the integral !
But I want to know if it is possible to do a specific method such as Simpson or by Usine Splines ?
I used interpolation to generate a function : But I have an error
Dl=[t,l];
x=Dl(:,1);
y=Dl(:,2);
plot(x,y,'*')
format long;
%Splines cubic
ys=spline(x,y)
ysplot=ppval(ys,t);
plot(x,y,'b*',t,ysplot,'r+',x,y2)
int=diff(fnval(fnint(ys),[0 4]))
The error is on the final line (int) : Array indices must be positive integers or logical values.
ys = struct with fields:
form: 'pp'
breaks: [1×96 double]
coefs: [95×4 double]
pieces: 95
order: 4
dim: 1
So I don't know if I can fix it ?
Thank you,
regards,
Sarah CHOUCHENE
2019년 11월 18일
Where ? Sorry, I don't understand you are talking about my program ? I didn't use diff.. diff is derivation in matlab..
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일
Hello sir,
Thank you for your answer
I did :
which fnint
which fnval
which diff
And I had this :
which fnval
C:\Program Files\MATLAB\R2019b\toolbox\curvefit\splines\fnval.m
>> which fnint
C:\Program Files\MATLAB\R2019b\toolbox\curvefit\splines\fnint.m
>> which diff
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\datafun\@char\diff) % char method
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일
Thank you,
I found that the probleme is ;
int = diff(temp3);
That means I have a probleme of array ..
when I try :
int=fnval(fnint(ys),[0 4])
it gives me :
int = 1×2
0 1.357601954491484
Sarah CHOUCHENE
2019년 11월 20일
And the diff.m is :
%DIFF Difference and approximate derivative.
% DIFF(X), for a vector X, is [X(2)-X(1) X(3)-X(2) ... X(n)-X(n-1)].
% DIFF(X), for a matrix X, is the matrix of row differences,
% [X(2:n,:) - X(1:n-1,:)].
% DIFF(X), for an N-D array X, is the difference along the first
% non-singleton dimension of X.
% DIFF(X,N) is the N-th order difference along the first non-singleton
% dimension (denote it by DIM). If N >= size(X,DIM), DIFF takes
% successive differences along the next non-singleton dimension.
% DIFF(X,N,DIM) is the Nth difference function along dimension DIM.
% If N >= size(X,DIM), DIFF returns an empty array.
%
% Examples:
% h = .001; x = 0:h:pi;
% diff(sin(x.^2))/h is an approximation to 2*cos(x.^2).*x
% diff((1:10).^2) is 3:2:19
%
% If X = [3 7 5
% 0 9 2]
% then diff(X,1,1) is [-3 2 -3], diff(X,1,2) is [4 -2
% 9 -7],
% diff(X,2,2) is the 2nd order difference along the dimension 2, and
% diff(X,3,2) is the empty matrix.
%
% See also GRADIENT, SUM, PROD.
% Copyright 1984-2005 The MathWorks, Inc.
% Built-in function.
Sarah CHOUCHENE
2019년 11월 20일
Thank you very much sir, I solved the problem of Diff.
Now I have to resolve how can I have the integration vectof of l=y. ^^
Thank you Walter Roberson.
Regards,
Sarah CHOUCHENE
2019년 11월 20일
I made a mistake, I added another variable Like you said before on the top of the code diff=abs(l1(1:80)-l(1:80)); and I forgot about it.. Thank you
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)