4 views (last 30 days)

So I'm trying to write code that calculates the following:

I have two functions of the same two variables, call them D(x,y) and T(x,y)

I'm trying to write a function that accepts inputs x,y,z and outputs:

So, there are two summations, the outer one takes the sum from i=0 up to min(x,y), and the inner sum takes the summation of terms from k=0 up to x-i

The inner sum isn't as complicated as it looks, it has a (-1)^k at the start and then just multiples the functions D(a,b) and T(a,b)^(z/2) where a and b depend on both where you are in the indexing of your outer summation and inner summation

This is a much harder proram than I have written before, so tips, insights, general advice, and even completed code are welcome!! Thanks for your time

Ameer Hamza
on 24 Sep 2020

Something like this should work

s = 0;

for i=0:min(x,y)

for k=0:x-1

s = s + (-1)^k * D(2*x-2*k-2*i, 2*y+2-2*i) * T(2*x-2*k-2*i, 2*y+2-2*i)^(z/2)

end

end

Ameer Hamza
on 24 Sep 2020

Yes, it is correct. k should be from 0 to x-i. How are you calling this function? I think that these outputs are displayed on the command window because you have put s after inner for-loop.

function sum = Sum(x,y,z)

s = 0;

for i=0:min(x,y)

for k=0:x-i

s = s + (-1)^k * QuantumDimension(2*x-2*k-2*i, 2*y+2-2*i) * Twist(2*x-2*k-2*i, 2*y+2-2*i)^(z/2);

end

s % remove this from here

end

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 0 Comments

Sign in to comment.