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!