MATLAB Answers

Is there any notation for the calculation of this sum ??

1 view (last 30 days)
I want to calculate a sum of products of the form :
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 ??

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 8 Oct 2012
Edited: Azzi Abdelmalek on 8 Oct 2012
a=[1 2 3 4];
p=[10 15 20 25]
% the result is
./ 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]
you can also create a function
f1=@(c,p1,p2,a,b) sum(c.*a.^p1.*b.^p2)

More Answers (2)

kamal kiki
kamal kiki on 8 Oct 2012
Thank you very much Abdelmalek for your answer.
I am still having a problem.
I have saved the M-file below under the name mytotal.m
function F = mytotal(c,p1,p2,a,b)
F = @(c,p1,p2,a,b)sum(c.*a.^p1.*b.^p2)
But when I enter in the command window the following command
mytotal([1.1 1.4 0.25 ],[2 7 6],[9 4 8],10,30) I have the following output
ans = @(c,p1,p2,a,b)sum(c.*a.^p1.*b.^p2) displayed in the command window.
Please what is wrong in my M-file ?????

Sign in to comment.

Wayne King
Wayne King on 8 Oct 2012
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)

Community Treasure Hunt

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

Start Hunting!