Group Abstract Group Abstract

Message Boards Message Boards

Solve a problem involving logical programming using "For" function?

Posted 8 years ago
Attachments:
POSTED BY: S G
Posted 8 years ago

This?

Fa = 3*V; Fb = 4*V; Fc = 5*V; Fd = 6*V;
a = 1; b = 1; c = 1; d = 1;
matrix = Table[
   If[Fb - Fa > 5, b = b + a; a = 0];
   If[Fc - Fb > 7, c = c + b; b = 0];
   If[Fd - Fc > 8, d = c + d; c = 0];
   {a, b, c, d}, {V, 20}];
ListPlot[Transpose[matrix], Joined->True, PlotLegends->{"a", "b", "c", "d"}]

enter image description here

There is a lot going on in that for someone who is new to Mathematica. {} and ; mean very different things in Mathematica than they do in other more "normal" programming languages. Search for some of those words and operators in the help system, see if you can try to understand why I did some of the things the way that I did, click on "Options and Details" in the help page to see more information.

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