Multiple Sum of Series in a Variable - Syntax Problem
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Christos Tsallis
el 24 de Mzo. de 2021
Comentada: Jan
el 25 de Mzo. de 2021
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 comentarios
Respuesta aceptada
Jan
el 24 de Mzo. de 2021
Editada: Jan
el 24 de Mzo. de 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 comentarios
Jan
el 25 de Mzo. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!