MATLAB Answers

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

1 view (last 30 days)
kamal kiki on 8 Oct 2012
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 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Azzi Abdelmalek on 8 Oct 2012
Edited: Azzi Abdelmalek on 8 Oct 2012
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 CommentsShowHide -1 older comments

Sign in to comment.

### More Answers (2)

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 ?????
##### 2 CommentsShowHide 1 older comment
kamal kiki on 9 Oct 2012
Ok thank you very much Abdelmalek.

Sign in to comment.

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)
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!
{"ft_lang_label":"__label__en","ft_lang_prob":0.9518648,"math_prob":0.93497854,"size":574,"snap":"2021-21-2021-25","text_gpt3_token_len":171,"char_repetition_ratio":0.1368421,"word_repetition_ratio":0.018867925,"special_character_ratio":0.31010452,"punctuation_ratio":0.147651,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99317783,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-06-21T17:53:45Z\",\"WARC-Record-ID\":\"<urn:uuid:6b7171c9-8f0e-4b42-94d0-7956e377b576>\",\"Content-Length\":\"141752\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:babe22f9-8417-4e23-a575-0d320f5db7b2>\",\"WARC-Concurrent-To\":\"<urn:uuid:2385bc2b-6869-423d-9bd2-3d045b552a2a>\",\"WARC-IP-Address\":\"104.110.193.39\",\"WARC-Target-URI\":\"https://www.mathworks.com/matlabcentral/answers/50137-is-there-any-notation-for-the-calculation-of-this-sum\",\"WARC-Payload-Digest\":\"sha1:DEWAQFZ3DCL24PF5CDA3OZGXRUYOLZGN\",\"WARC-Block-Digest\":\"sha1:EVPI7K3XNP4M5KDTCIXBXCODSNUWFJUX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-25/CC-MAIN-2021-25_segments_1623488286726.71_warc_CC-MAIN-20210621151134-20210621181134-00595.warc.gz\"}"}