How I can integrate function if I have two variables?

Hi:
I am using trapz to integrate my function, but in my function I have two variables, what should I do if I want to integrate only one variable and keep the other one? if anyone can help me, I will be appreciate it.
Thank you
Subinuer

댓글 수: 1

Suppose you have f(x,y) and you want to integrate from A to B over x with y=y0. Then
y=y0
fun2=@(x)fun(x,y0)
result=integral(fun2,A,B)

댓글을 달려면 로그인하십시오.

 채택된 답변

Star Strider
Star Strider 2014년 6월 30일
If you have already evaluated your function and have a matrix of (x,y) values for it, you can use trapz to integrate it in the dimension you want.
Example:
f = @(x,y) 3*x.^2 + 5*y.^3;
x = 0:0.1:5;
y = 0:0.1:7;
[X, Y] = meshgrid(x,y);
fmtx = f(X,Y);
fxint = trapz(x,fmtx,2);
figure(1)
surfc(X,Y,fmtx)
grid on
xlabel('X')
ylabel('Y')
Otherwise, you need to do the integration with the Symbolic Math Toolbox:
syms x y
f(x,y) = 3*x.^2 + 5*y.^3;
fint = int(f, x)

댓글 수: 6

ok, thank you for your answer. I tried with traps, because I want to express all the function with y(one of the variable) after integrating, I don't have any value for y, after integrating I need to solve a matrix equation to find y. So do you think traps is working for me? if I use int, after integrating, it is in the syms form, how can I solve that one?
My pleasure!
However, I do not understand your function, your data, or what you want to do. You can use matlabFunction (Symbolic Math Toolbox) to create an anonymous function (or function file) from your partially-integrated function as a function of the remaining variable.
Thank you, I will try like this.
My pleasure!
I was using "integral" function which didnt work, when I switched to this "int" function, it started working. Thanks!
My pleasure!
The trapz function integrates vectors and matrices numerically.
The integral function integrates functions numerically.
The int function integrates symbolic expressions and functions, and vpaintegral integrates them numerically.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

질문:

2014년 6월 30일

댓글:

2021년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by