[Date Index]
[Thread Index]
[Author Index]
Re: Problem with If statement in a Do or a While loop
*To*: mathgroup at smc.vnet.net
*Subject*: [mg39456] Re: [mg39437] Problem with If statement in a Do or a While loop
*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>
*Date*: Sun, 16 Feb 2003 06:14:11 -0500 (EST)
*Sender*: owner-wri-mathgroup at wolfram.com
Because you do not provide the values needed to run your program it is
impossible to answer your question without very detailed examination of
your code. Perhaps somebody will have the time to do that. However, let
me point out that If may produce no output when Mathematica can't
verify whether a statement is true or untrue for example:
If[x>2,Print[3],Print[4]]
If[x>2,Print[3],Print[4]]
Since Mathematica does not know the value of x it just returns the
input. In such cases you cna use If with an extra argument:
If[x>2,Print[3],Print[4],Print[5]]
5
This may or may not apply to your case.
Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/
On Saturday, February 15, 2003, at 03:42 PM,
A.Reinstaller at MERIT.unimaas.nl wrote:
> There is a problem I continue to have, perhaps one knows what's wrong.
> I
> try to check the values generated by an interpolating function. I do
> so by
> using a Do loop in which I ask whether the function has reached some
> value
> within a small intervall and if so to write the time tag of the first
> hit
> out. Now, when running the program it does not step into the IF
> evaluations.
> I have added an else branch to be sure that even if the condition was
> not
> true something would be written out. I have also checked whether the
> values
> of the interpolating function are correctly extracted as well as
> whether
> they were really lying in the intervall asked for in the IF statement.
> In
> top of that I varied the stepsize to a minimal and increased the
> margins of
> the intervall. I used also a While instead of a Do loop. But in any
> case
> neither the THEN nor the ELSE branch "fired", telling me that the IF
> statement is not checked. WHY????
>
>> Is there some restriction for the use of IF clauses in loops in
>> Mathematica? Otherwise I could not explain why nothing happens. I
>> checked
>> in the manual but nothing was mentioned.
>>
>> Thanks for your forthcoming help. Andreas
>>
>> Here is the code:
>>
>> solutionIncome=
>> NDSolve[Join[veblen07,IvaluesIncome],{x1,x2,y1,y2,py},{t,0,Tmax}];
>>
>> S={(q1*y1[t]+q2*y2[t])/.solutionIncome/.t->Tmax};
>> c10=S*0.01; c90=S*0.9;
>> t10=0;t90=0; \[CapitalDelta]t=0;
>> tol=0.1; stept=Tmax*0.0001;
>>
>> Do[ {
>> y=(q1*y1[t]+q2*y2[t])/.solutionIncome/.t->\[Theta];
>> If[ ( (y>(c10-(c10*tol) )|| y<(c10+(c10*tol)) ) && t10 ==0
>> ) ,( t10=\[Theta]; Print["t10 found"]; Continue[] ) , (Print["t10 not
>> found"]; Continue[]) ];
>> If[ ( ( y>(c90-(c90*tol)) || y<(c90+(c90*tol)) ) && t90
>> ==0 ) ,(t90=\[Theta]; Print["t90 found"]; Continue[]), (Print["t90
>> not
>> found"]; Continue[]) ];
>> If[ (t10>0) && (t90>0),(\[CapitalDelta]t=t90-t10;
>> Continue[]) ];
>> },
>> {\[Theta],0,Tmax,stept}];
>>
>>
>>
>
>
>
Prev by Date:
**Simplify a module**
Next by Date:
**Re: Bug in ColorFunctionScaling ???**
Previous by thread:
**Problem with If statement in a Do or a While loop**
Next by thread:
**RE: Re: Problem with If statement in a Do or a While loop**
| |