how to integrate over array boundaries
24 次查看(过去 30 天)
显示 更早的评论
Hi Guys ,
I want to write a code which includes an array like x=[1 2 3;4 5 6] and
my function is
f=@(y) (y-x).^2
and
Q= integral ( f,0,x);
. I couldn't be successful about it and I need help how can I take an integral over array boundries like this.
Thanks.
0 个评论
回答(3 个)
Roger Stafford
2015-3-19
If you consult the website:
http://www.mathworks.com/help/matlab/ref/integral.html
you will find that 'integral' does not accept arrays for its integration limits. You must use scalar (individual numbers) quantities for these limits. This means of course that you will have to use for-loop constructs to compute Q in a corresponding matrix for each of the separate values in x.
0 个评论
Mike Hosea
2015-3-19
编辑:Mike Hosea
2015-3-19
Two steps to set it up. First make it work with a scalar x:
>> Qscalarx = @(x)integral(@(y)(y - x).^2,0,x);
Now vectorize it with ARRAYFUN:
>> Q = @(x)arrayfun(Qscalarx,x);
Now use it.
>> Q([1 2 3;4 5 6])
ans =
0.33333 2.6667 9
21.333 41.667 72
4 个评论
Mike Hosea
2015-3-20
Then you need to put p(w) in there everywhere you have just p, and each term involving w anywhere must use an element-wise operator rather than a matrix operator when it connects with other terms depending on w.
Qscalarx = @(x)integral(@(w)k1*(x-w)*(k*l*vi/(wr*ccons)).*(((1+p(w)*l)*vi/ccons).^(k-1)).*2.71.^((-((1+p(w)*l)*vi/ccons)).^k),0,x);
I'd probably define a couple of constants here.
c1 = kr*(k*l*vi/(wr*ccons));
c2 = vi/ccons;
Qscalarx = @(x)integral(@(w)c1*(x-w).*(((1+p(w)*l)*c2).^(k-1)).*2.71.^((-((1+p(w)*l)*c2)).^k),0,x);
Salah Djerouni
2020-2-8
if you possible to help me ,i want to calculate intensity arrias with the equation below in matlab sure :
with
a(t) is vector of acceleration
and
t : is vector of time
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!