Multiple Sum of Series in a Variable - Syntax Problem
4 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I got a problem expressing the equations bellow, in matlab. There is a dat variable which is a 7x2 table and has values in it. I must create a function wich will have "dat" as an input and "a" as an output. So if we go to the first "symsum" of SSxy equation I want to express "for j=1 to P do the sum of series of Xj*Yj" as it is shown bellow in the code. The problem is that I got errors and I must have the syntax of symsum wrong. Can someone help me understand my mistake? Thanks for your time, appreciate your help!
dat - variable
1000 79
3000 71
9000 59
50000 49
93000 39
223000 33
510000 24
function [a]=Example(dat)
x=log10(dat(:,1));
y=dat(:,2);
P=length(dat);
syms x y
SSxy=(symsum(x(j)*y(j),j,1,P))-(((symsum(x(j),j,1,P))*(symsum(y(j),j,1,P)))/P);
SSxx=(symsum(x(j).^2,j,1,P))-(((symsum(x(j),j,1,P))^2)/P);
a=SSxy/SSxx;
end
0 件のコメント
採用された回答
Jan
2021 年 3 月 24 日
編集済み: Jan
2021 年 3 月 24 日
Why do you try a symbolic sum, when your input is numerical? Here a numerical summation:
function a = Example(dat)
x = log10(dat(:, 1));
y = dat(:, 2);
P = size(dat, 1); % Safer than length(dat)
% X.' * y is the dot product, same as sum(x .* y)
SSxy = x.' * y - sum(x) * sumy(y) / P;
SSxx = x.' * x - sum(x)^2 / P;
a = SSxy / SSxx;
end
2 件のコメント
Jan
2021 年 3 月 25 日
symsum creates a symbolic formula. You could create it and evaluate the result for numeric input. But this is ways slower than the direct numeric summation.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!