How to graph a function that consists of summations?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tessla Carlsson
am 21 Sep. 2021
Beantwortet: Mathieu NOE
am 21 Sep. 2021
I am trying to graph a fucntion C that includes four different summations. What I have so far is:
g=ga;
T=(0.1:0.001:1);
F1 = sum(-(E.^2)*g*exp(-(E-13)./T),E,0,13);
F2 = sum(-g*exp(-(E-13)./T),E,0,13);
F3 = sum(E*g*exp(-(E-13)./T),E,0,13);
F4 = sum((g*exp(-(E-13)./T)),E,0,13);
C = (1/(T^2))*((F1/F2)-(F3/F4)^2)
Where ga is an array and E goes from 0 to 13. T is a value that increases in 0.001 increments from 0.1 to 1.
I am a little lost as to what to do from here to fix my summations so that I no longer get errors and how to plot C. (I also tried to run each summation as a symsum, with syms E).
Any help is appreciated!
0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 21 Sep. 2021
hello
I tried this code
clc
clearvars
% g=[1;2;3];
g=[1]; % same curves - whatever g value is
% T=(0.1:0.01:1);
T=logspace(-1,0,50); % better rendering IMHO
E = linspace(0,13,130);
for ci = 1:length(g)
C(ci,:) = computeC(g(ci),T,E);
end
plot(T,C,'-*');
xlabel('T');
ylabel('C');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function C = computeC(g,T,E)
% F1 = sum(-(E.^2)*g*exp(-(E-13)./T),E,0,13);
% F2 = sum(-g*exp(-(E-13)./T),E,0,13);
% F3 = sum(E*g*exp(-(E-13)./T),E,0,13);
% F4 = sum((g*exp(-(E-13)./T)),E,0,13);
for ci = 1:length(T)
F1 = sum(-(E.^2).*g.*exp(-(E-13)./T(ci)));
F2 = sum(-g.*exp(-(E-13)./T(ci)));
F3 = sum(E.*g.*exp(-(E-13)./T(ci)));
F4 = sum(g.*exp(-(E-13)./T(ci)));
C(ci) = (1/(T(ci)^2))*((F1/F2)-(F3/F4)^2);
end
end
and finally found out that whatever the value of g , the result in C does not change. Looking again at the equations it's obvious that g appears both at the numerator and denominator each time so it will cancel out when you do F1/F2 and F3/F4
got this plot :
0 Kommentare
Weitere Antworten (1)
Walter Roberson
am 21 Sep. 2021
g = ga(:);
T=(0.1:0.001:1);
E = reshape(0:13, 1, 1, []) ;
F1 = sum(-(E.^2).*g.*exp(-(E-13)./T),3);
F2 = sum(-g.*exp(-(E-13)./T),3);
F3 = sum(E.*g.*exp(-(E-13)./T),3);
F4 = sum((g.*exp(-(E-13)./T)),3);
C = (1./(T.^2)).*((F1./F2)-(F3./F4).^2);
This should be numel(g) by numel(T)
If you are thinking of plotting then
plot(T, C.')
if you want there to be numel(g) different lines.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!