Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Nested loop error' topicStudent Support Forum > General > "Nested loop error"

Next Comment >Help | Reply To Topic
Author Comment/Response
elloa
09/28/11 09:47am

Hey guys,

I'm new in Mathematica. I need to perform a nested loop and use the values of the iterator variables in order to calculate a certain value.

Here is the general idea of my code:

for c,d = o to 7 [
cost = 0.0
vx = 0.0
for a,b = 0 to 5
vx += ((2*Pi*I*(a*c + b*d))/8)
]
cost = vx/48;
]

In Mathematica I wrote that as

For[c = 0, c <= 7, c++,
For[d = 0, d <= 7, d++,

vx = 0.0;
cost = 0.0;

For[a = 0, a <= 5, a++,
For[b = 0, b <= 5, b++,
vx += ((2*Pi*I)/8)*(a*c + b*d);
] (*b iteration *)
] (* a iteration*)
cost = vx/48;
Print[cost]




] (* d iteration *)
] (* c iteration *)



However, I keep getting the error
Set::write: "Tag Times in 0.\ Null is Protected"

I don't understand this problem exactly. Can anyone give me a help? What does it means and Why this is happening?

URL: ,

Subject (listing for 'Nested loop error')
Author Date Posted
Nested loop error elloa 09/28/11 09:47am
Re: Nested loop error Forum Modera... 09/28/11 12:13pm
Re: Re: Nested loop error elloa 09/28/11 2:14pm
Next Comment >Help | Reply To Topic