MATLAB: How do is code this last summation? I was able to do the first one but have no clue how to finish it

multiple summationsneed help pleasesenior project

Matlab question.GIF
function Senior_Project_code
%input values
y = 4;
n = 1;
L = 3;
%equations
%z=17;
a=L/(2*n);
x = 0:1:L;
E = 808/(y^2);
%c = atan(abs((x-a(2*i-1)))/y)*(180/3.14);
%s = (-0.0000000667*atan(abs((x-a(2*i-1)))/y)*(180/3.14).^4 ...
% + 0.0000157209*atan(abs((x-a(2*i-1)))/y)*(180/3.14).^3 ...
% - 0.0010081511*atan(abs((x-a(2*i-1)))/y)*(180/3.14).^2 ...
% + 0.0020817855*atan(abs((x-a(2*i-1)))/y)*(180/3.14) ...
% + 0.9991821678);
Axx(x+1) = 0;
for k = 1:n
Axx(x+1) = Axx(x+1) + E* ...
(-0.0000000667*(atan(abs((x-a*(2*k-1)))/y)*(180/3.14)).^4 ...
+ 0.0000157209*(atan(abs((x-a*(2*k-1)))/y)*(180/3.14)).^3 ...
- 0.0010081511*(atan(abs((x-a*(2*k-1)))/y)*(180/3.14)).^2 ...
+ 0.0020817855*(atan(abs((x-a*(2*k-1)))/y)*(180/3.14)) ...
+ 0.9991821678);
end
Ax = sum(Axx)/(L+1); %can I redo this to match my other equation?
display (Axx,'Brightness Values');
display (Ax,'Average Brightness');
end
Any help redoing Ax to match my above summation with i=1, to z-2… would be much appreciated.
Coding should be in for,if, then, and, or….type statements if possible.

Best Answer

Maybe a little bit clearer version:
y= 7.5, n=16, L=16 result: 118.22
y= 4, n=1, L=3 result: 46.31
function main
% input values
y = 4;
L = 3;
z = 17;
n = 1;
av = 0;
for i = 1:z-2
x = L/(z-1)*i;
av = av + s(x,y,n,L);
end
x = L/(2*z-2)*i;
av = av + s(x,y,n,L) + s(L-x,y,n,L);
av = av/z;
display('Average Brightness: '), av
end
function result = s(x,y,n,L)
% equations
E = 808.01/y^2.008;
a = L/(2*n);
c = @(i) atand( abs(x-a*[2*i-1])/y );
coeff = [
-0.0000000667
0.0000157209
-0.0010081511
0.0020817855
0.9991821678];
S = 0;
for i = 1:n
for j = 1:5
S = S + coeff(j)*c(i)^(5-j);
end
end
result = E*S;
end
Related Question