Multiple Sum of Series in a Variable - Syntax Problem
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Jan
il 24 Mar 2021
Modificato: Jan
il 24 Mar 2021
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 Commenti
Jan
il 25 Mar 2021
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!