how to calculated integral of multiplying two function handle that changed by loop
조회 수: 15 (최근 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!