現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)