Need help programming a few tricky calculations!!
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Michael Vaughan
am 26 Sep. 2020
Kommentiert: Alan Stevens
am 26 Sep. 2020
Can somebody show me how to write a program to calculate a program that you input and N and the output is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/366856/image.png)
thank you
edit: in regualer text rather than attempt to write latex:
f(n) = [ ( (-1)^(n-1)*t^(2-2n) ) / ( 1-t^(-4) ) ] sum_k=0^{n-1} t^-4nk product_{i=0}^k (1-t^(4i-4n))
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 26 Sep. 2020
Here is one way to do the function, assuming you are looking for a numerical output, and that you pass it t as well as n:
n = ... % choose your number
t = ... % ditto
output = fn(n,t);
function f = fn(n,t)
c = (-1)^(n-1)*t^(2-2*n)/(1-t^-4);
S = 0;
for k = 0:n-1
tm = t^(-4*n*k);
P = 1;
for i = 0:k
P = P*(1-t^(4*i-4*n));
end
S = S + tm*P;
end
f = c*S;
end
2 Kommentare
Alan Stevens
am 26 Sep. 2020
You would have to give the script a different name, not fn. These sorts of functions (like fn) always come at the end of the script.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Other Formats finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!