How I can integrate function if I have two variables?
43 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Subinuer
am 30 Jun. 2014
Kommentiert: Star Strider
am 22 Mär. 2021
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 Kommentar
Laurence Lurio
am 2 Feb. 2017
Bearbeitet: Laurence Lurio
am 2 Feb. 2017
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)
Akzeptierte Antwort
Star Strider
am 30 Jun. 2014
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 Kommentare
Sinipelto
am 22 Mär. 2021
I was using "integral" function which didnt work, when I switched to this "int" function, it started working. Thanks!
Star Strider
am 22 Mär. 2021
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!