Message Boards Message Boards

how to use the "For" here

Posted 9 years ago

I want to use "For" here in order to let mathematica calculate my "body-part" several times. But my "body-part" seem a bit large. And then, lot of errors appear. The strange is when I repeat the calculation by my hand that just as "For" should do (just only delete the For[...]), the programm worked. How can I solve my problem?

Programm:

enter image description here

POSTED BY: YU SHANG
7 Replies

Where are the variables inside ClearAll defined in your program? It looks like your problem is that you're giving For 2 arguments instead of the nominal 4. Take a look at For's documentation for more information.

Note that For is generally considered bad practice in the Wolfram Language, as there is usually a more elegant way to accomplish a task.

POSTED BY: Jesse Friedman
Posted 9 years ago

The variables inside ClearAll are used in the 2 NDSolve.

POSTED BY: YU SHANG

OK, I see. May I ask what you're trying to accomplish by using For?

POSTED BY: Jesse Friedman
Posted 9 years ago

I want to calculate the 2 NDSolve many times with different parameters automaticly. The attachment is my programm.

Attachments:
POSTED BY: YU SHANG

Try this modified version. I replaced the Fors with Tables.

Attachments:
POSTED BY: Jesse Friedman

Actually, ignore that. Your problem is that you're using % to reference the result of the previous computation, but % is the output of the most recent cell, not the last line. Try this attachment.

Attachments:
POSTED BY: Jesse Friedman
Posted 9 years ago

Thank you very very much, the problem is exactly what you said that happened at %. Now, it works! Thanks again!

POSTED BY: YU SHANG
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract