Code is not working, can someone help me?

So I have successfully written scripts for three different functions of 3 variables, Sum1(x,y,z) Sum2(x,y,z) and Sum3(x,y,z)
I have 2 other scripts for functions of just two of these variables: QuantumDimension(x,y) and Twist(x,y)
I'm trying to relate these functions as so:
function c = CJ(x,y,z)
c = (Twist(x,y)^(-2*z)/QuantumDimension(x,y))*(Sum1(x,y,z)+Sum2(x,y,z)-Sum3(x,y,z))
end
So Twist^(-2z) divided by the QuantumDimension, multipled by the sum of the three summations, (Sum1 + Sum2 + Sum3)
This is the output I get when I try to run the code:
Error in CJ (line 2)
c = (Twist(x,y)^(-2*z)/QuantumDimension(x,y))*(Sum1(x,y,z)+Sum2(x,y,z)-Sum3(x,y,z))
I do not see anything wrong with this line!! Insights appreciate, thanks for being patient.

5 个评论

What is the full error message (all the red text)? And how are you calling this function?
Here is the error message:
__________________
Output argument "sum" (and maybe others) not assigned during call to "Sum1".
Error in CJ (line 2)
c = (Twist(x,y)^(-2*z)/QuantumDimension(x,y))*(Sum1(x,y,z)+Sum2(x,y,z)-Sum3(x,y,z))
__________________
i am calling the function by typing
CJ(3,2,2)
Rik
Rik 2020-9-24
编辑:Rik 2020-9-24
How did you define the Sum1 function?
Also note that using sum as a variable name is generally not a good idea, as it will then shadow the built-in function.
Also, is the minus sign intential before Sum3?
Here is the code for Sum1
function sum = Sum1(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+k-2*i) * Twist(2*x-2*k-2*i, 2*y+k-2*i)^(z/2);
end
end
s
The minus sign is indeed intentional
Thanks for the tips! I really appreciate them
I renamed sum to be s1 and now I get this error message:
Output argument "s1" (and maybe others) not assigned during call to "Sum1".
Error in CJ (line 2)
c = (Twist(x,y)^(-2*z)/QuantumDimension(x,y))*(Sum1(x,y,z)+Sum2(x,y,z)-Sum3(x,y,z))

请先登录,再进行评论。

回答(1 个)

This should fix it:
function s = Sum1(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+k-2*i) * Twist(2*x-2*k-2*i, 2*y+k-2*i)^(z/2);
end
end
end

2 个评论

Thanks man!! Much Appreciated!!
Another question: If I wanted to change CJ(x,y,z) to be a function of two variables whilst keeping z as an indeterminant, how would I have to alter my scripts?? I went through the scripts on Sum1, Sum2, Sum3, QuantumDimension and Twist and added syms z and turned them all into functions of two variables, but that didn't seem to work.
What do you mean by that? Do you want to provide z at a later time than x and y? Like a lambda? You can probably get most of the way there with an anonymous function.
Note that I didn't make an attempt to simplify or speed up your code, so the current shape of your functions may not allow you to do what you want.

请先登录,再进行评论。

类别

标签

评论:

Rik
2020-9-24

Community Treasure Hunt

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

Start Hunting!

Translated by