Is there any notation for the calculation of this sum ??
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to calculate a sum of products of the form :
1.1*a^2*b^9+1.4*a^7*b^4+0.25*a^6*b^8
where a and b are constants.
This expression is the sum of 3 products, I am giving it just for simplification, but the reality is that I have to calculate a sum of 47 products of this form and in each product the coefficients (1.1, 1.4, 0.25) are different and the powers (2, 9, 7, 4, 6, 8) are also different from one product to the other.
So, my question is : Is there any notation that I can use to calculate the sum above without having to repeat each time the constants a and b ??
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2012년 10월 8일
편집: Azzi Abdelmalek
2012년 10월 8일
example
x=11
a=[1 2 3 4];
p=[10 15 20 25]
sum(a.*x.^p)
% the result is
a(1)*x^p(1)+a(2)*x^p(2)+...
./ and .* and .^ are operations element by element
for your case
c=[1.1 1.4 0.25 ]
p1=[2 7 6]
p2=[9 4 8]
a=10;b=30
out=sum(c.*a.^p1.*b.^p2)
you can also create a function
f1=@(c,p1,p2,a,b) sum(c.*a.^p1.*b.^p2)
then
out=f1(c,p1,p2,a,b)
댓글 수: 0
추가 답변 (2개)
kamal kiki
2012년 10월 8일
댓글 수: 2
Azzi Abdelmalek
2012년 10월 8일
Kamal it's not a function file. just write
f1=@(c,p1,p2,a,b) sum(c.*a.^p1.*b.^p2)
then
c=[1.1 1.4 0.25 ]
p1=[2 7 6]
p2=[9 4 8]
a=10;b=30
out=f1(c,p1,p2,a,b)
Wayne King
2012년 10월 8일
Why are you entering it like that?
mytotal = @(c,p1,p2,a,b)sum(c.*a.^p1.*b.^p2)
mytotal([1.1 1.4 0.25 ],[2 7 6],[9 4 8],10,30)
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!