how to calculated integral of multiplying two function handle that changed by loop
16 ビュー (過去 30 日間)
古いコメントを表示
hi guys
i have two function like these:
f(x,y)=(i+1)x+(j-1)y
g(x,y)=(i-1)x+(j-1)y
(real functions are more complex that here)
now i want to calculate integral of h(x,y)=f*g when f & g change by loops depend on i & j.
i want to write these function in a new mfile & use of them in my code. but i don't know hoe i can do this.
actually i want do like bellow.
for i=1:n
for j=1:m
h=@(x,y)(f*g)
l=integral2(h,-1,1,-1,1)
end
end
that f & g are functions like this.
function d=f(i,j)
f(x,y)=(i+1)*x+(j-1)*y
end
i know cods are incorrect but wrote these to saying what i want to do.
function are complex & i should use them several times in my code so i cant write them in it.
thank u for answering :)
1 件のコメント
Walter Roberson
2016 年 12 月 14 日
for i=1:n
for j=1:m
h =@(x,y) f(x,y,i,j) * g(x,y,i,j);
l = integral2(h,-1,1,-1,1)
end
end
function d = f(x, y, i, j)
d = (i+1).*x + (j-1).*y;
end
回答 (2 件)
Steven Lord
2016 年 12 月 14 日
A 1-dimensional example:
fun1 = @(x) sin(x);
fun2 = @(y) cos(y);
fun3 = @(z) fun1(z).*fun2(z);
integral(fun3, 0, 1)
To check, explicitly specify the function in the integral call:
integral(@(x) sin(x).*cos(x), 0, 1)
Another check is to perform the integration symbolically with the int function from Symbolic Math Toolbox. The vpa call just displays the answer in a format that's easier to compare with the numeric answers.
syms q
vpa(int(sin(q)*cos(q), q, 0, 1))
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!