How to use integration function?

8 ビュー (過去 30 日間)
Anirudh
Anirudh 2014 年 2 月 27 日
編集済み: Wayne King 2014 年 2 月 27 日
Hi, I'm trying to solve an integration solution. I have addressed all errors but am unable to run the program. Could anyone please help me? FYI, I'm using MatLab R2013b.
C0 = 10; Dx = 1; Vx = 0.1; x = 30; e = (Vx*x)/(4*Dx); C = 1:500;
for t = 1:500
a = x/(2*sqrt(Dx*t));
p = x/(2*sqrt(Dx*t));
m = C0*(2/sqrt(pi))*exp(((Vx^2)*t)/(4*Dx));
fun1 = exp((-p.^2)-((e^2)/(p^2)));
fun2 = exp((-p.^2)-((e^2)/(p^2)));
n = int(fun1,p,0,4);
o = int(fun2,p,0,a);
C(t) = m*(n-o);
end
t = 1:500;
plot(t,C,'r.')
The error I'm getting off this code is:
Undefined function 'int' for input arguments of type 'double'. Error in Sample (line 16) n = int(fun1,p,0,4);
If anyone can tell me how to use the integration function, it would be very useful. Thank you

回答 (1 件)

Wayne King
Wayne King 2014 年 2 月 27 日
編集済み: Wayne King 2014 年 2 月 27 日
int() is for symbolic function. Use integral with a function handle. Or use one of the other numerical routines, trapz(), cumtrapz()
For example to approximate the antiderivative of cos(t) from -pi to pi
dt = 0.01;
t = -pi:dt:pi;
x = cos(t);
y = cumtrapz(x);
y = y.*dt;
plot(t,x); hold on;
plot(t,y,'r');
legend('cos(t)','sin(t)')

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by