define a function which computes numerical integral

3 ビュー (過去 30 日間)
giorgione palma
giorgione palma 2017 年 4 月 13 日
コメント済み: Torsten 2017 年 4 月 13 日
Given 2 function f=@(x),g=@(x) I would like to define the function cg1return =@(t) int(f(s) * int(g(z), z == (0..s)), s == (0..t)) which gives to me the the result of the numeric integral from 0 to t. In other words it takes as input the extreme of integration "t" and gives me back the result of this nasty double integral.

回答 (1 件)

Torsten
Torsten 2017 年 4 月 13 日
function main
t = ...;
cg1return = integral(@fun,0,t);
function y = fun(s)
f = @(s)...;
g = @(z)...;
for i=1:numel(s)
y(i) = f(s(i))*integral(g,0,s(i));
end
But my first solution was much more efficient :-)
Best wishes
Torsten.
  2 件のコメント
giorgione palma
giorgione palma 2017 年 4 月 13 日
Thank you, but I don't understand how are the function @fun and the vector "s" defined.
Torsten
Torsten 2017 年 4 月 13 日
@fun is defined as a function routine which is below the call "cg1return = integral(@fun,0,t);"
The vector s does not need to be defined by you. You only have to fill in the functions f and g and the end point t of integration.
Best wishes
Torsten.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by