I'm trying to optimize some kind of process in Mathematica. I did it without any problems in Matlab and now I'm trying to do the same in Mathematica which I don't know at all. I'm trying to find the best value of variable u for my proces, but that's not what I'm going to ask. My code at least should print eleven values of variable 'wynik' but it doesn't. I suppose that I've got some stupid and minor mistake in syntax, but as I've said earlier - I'm new at Mathematica environment. Any thoughts?
For[u == 1, u <= 1, u == u + 0.1,
s = NDSolve[{x1'[t] == u*(10*x2[t] - x1[t]), x1[0] == 1,
x2'[t] == u*(x1[t] - 10*x2[t]) - (1 - u)*x2[t], x2[0] == 0},
{x1, x2}, {t, 0, 1}];
wynik == 1 - Evaluate[{x1[1] /. s} + {x2[1] /. s}];
Print[wynik]]
For[u == 1, u <= 1,
so how do you expect this to run 11 times? try may beFor[u = 0, u <= 1
..... (note also difference between=
and==
). These are not the same in Mathematica. see help on reference.wolfram.com/language/ref/For.html also better to useDo
if you need to make explicit loops. $\endgroup$For
, and probably not evenPrint
(I admit, I used it quite a bit 20 years ago when I was green). Instead, you should considerFunction
s,Table
s, or other functional concepts. My personal preference is to avoid imperative programming and explicit loops whenever practical. Mathematica is really suited for this approach, and as a result you'll feel a lot less like you're fighting against it. $\endgroup$