Problem with conditional statement in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter projektMayhem
  • Start date Start date
  • Tags Tags
    Conditional Mathematica
Click For Summary
SUMMARY

The forum discussion centers on an issue encountered while using Mathematica 5.0 to evaluate a conditional statement within a Do loop while iterating a solution to a non-linear differential equation. The user reported that the output was incorrect, producing i^2 instead of the expected value of q, which should always be less than or equal to 1. The problem was resolved, indicating that the initial code had a logical flaw that was corrected.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of non-linear differential equations
  • Knowledge of NDSolve function in Mathematica
  • Basic concepts of iterative loops in programming
NEXT STEPS
  • Review Mathematica's documentation on the Do loop syntax
  • Explore advanced features of NDSolve for solving complex differential equations
  • Learn about debugging techniques in Mathematica to identify logical errors
  • Investigate conditional statements in Mathematica for proper evaluation
USEFUL FOR

Mathematica users, mathematicians, and engineers working with differential equations who seek to improve their coding skills and troubleshoot common programming issues.

projektMayhem
Messages
4
Reaction score
1
I am trying to iterate a solution to a non-linear differential equation - but I am unable to evaluate a statement within a Do loop

Code:

Do[q = Cos[Evaluate[x'/.up]]; If[ q <= 1, Print[q], Print, Print[i^2]], {i, 0.1, 1, .1}]

x' is a solution to NDSolve

The output is i^2, which is absurd as q is necessarily <= 1.

In other words, it's not properly evaluating the conditional statement. I am lost as what to do with this, any help is greatly appreciated.

edit: I'm using Mathematica 5.0
 
Physics news on Phys.org
Nevermind, problem resolved.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K