How to evaluate sigma (summation) expression using meshgrid() and sum()?

3 ビュー (過去 30 日間)
Yuval
Yuval 2013 年 3 月 27 日
I would like to evaluate the following expression using functions meshgrid, sum and dot operations: y = Ʃ(n=1 to N) xn*[cos(x2 + n2)/xn], where x is the vector of four equally spaced values from 1 to 2, N=10.
I wish to verify whether this is how it should be done:
n = 1:10;
x = linspace(1,2,4);
[X,N] = meshgrid(x,n);
y1 = (X.^N).*((cos(X.^2 + N.^2))./(X.*N));
y = sum(y1);
  2 件のコメント
Chaitanya Chitale
Chaitanya Chitale 2013 年 3 月 27 日
Yuval,
Could you confirm that the equation is: y = Ʃ(n=1 to N) xn*[cos(xn^2 + n^2)/xn]
Yuval
Yuval 2013 年 3 月 27 日
I am terribly sorry, the expression should have been: Ʃ(n=1 to N) [(x^n)*(cos(x^2 + n^2)/xn)]

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2013 年 3 月 27 日
"the expression should have been: Ʃ(n=1 to N) [(x^n)*(cos(x^2 + n^2)/xn)]"
well I would think that xn is the nth element of x and so should be just X. So the equation would be
y1 = (X.^N) .* cos(X.^2 + N.^2) ./ X;
Final Code
clc;
clearvars;
n = 1:10
x = linspace(1,2,4)
[X,N] = meshgrid(x,n)
y1 = (X.^N) .* cos(X.^2 + N.^2) ./ X
  1 件のコメント
Yuval
Yuval 2013 年 3 月 27 日
Typing xn, I took it for granted x*n was understood. Pardon me for that. Would you now please care to evaluate my original code (my first post)?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by