Why Does DSolve Work with s[x] but Not y[x] in Mathematica?

  • Context: Mathematica 
  • Thread starter Thread starter Shinaolord
  • Start date Start date
  • Tags Tags
    Mathematica Strange
Click For Summary

Discussion Overview

The discussion revolves around the behavior of the DSolve function in Mathematica when using different variable names, specifically comparing the use of y[x] and s[x]. Participants explore the reasons behind an error encountered with y[x] and propose various troubleshooting steps.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports an error when using DSolve with y[x] and suggests that y[x] may have been assigned a value previously.
  • Another participant attempts to clear the variable using Clear[y] and Clear[y,x], but finds that it does not resolve the issue.
  • A suggestion is made to use Clear[y[x]] to remove the specific function definition, but this also fails, leading to confusion about the behavior of Clear.
  • Participants discuss the difference between Clear and Remove, with one noting that Clear may not fully eliminate the variable as expected.
  • One participant shares an example where DSolve works with y[x] after clearing it, indicating that the issue may be context-dependent.
  • Another participant expresses interest in seeing a practical example of when Remove is necessary over Clear, indicating a desire for deeper understanding.
  • One participant mentions that restarting Mathematica did not resolve the issue, but using a different copy of the assignment allowed DSolve to work with y[x].

Areas of Agreement / Disagreement

Participants do not reach a consensus on the underlying cause of the issue with y[x]. There are multiple competing views regarding the effectiveness of Clear versus Remove and the persistence of variable definitions in Mathematica.

Contextual Notes

There are limitations in understanding how variable definitions persist in Mathematica, particularly regarding the behavior of Clear and Remove functions. Some participants express uncertainty about the effectiveness of their troubleshooting steps.

Who May Find This Useful

This discussion may be useful for Mathematica users encountering issues with variable definitions and the DSolve function, particularly in the context of differential equations.

Shinaolord
Messages
92
Reaction score
4
So when i use the following command, I get the following error
DSolve[y'[x] - y[x] == 3, y[x], x]
DSolve::deqn: Equation or list of equations expected instead of False in the first argument False. >>

But when i change the variable y[x] and y'[x] to s[x] and s'[x], It works
why is this?
In[185]:= DSolve[s'[x] - s[x] == 3, s[x], x]

Out[185]= {{s[x] -> -3 + E^x C[1]}}
 
Physics news on Phys.org
Most likely y[x] has been given some value earlier.
 
I tried clearing it with clear all and clear [f,y,x] but it still doesn't work. I think it's strange, maybe y didn clear properly?
 
Clear[y] won't clear y[x]. Try Clear[y[x]].
 
Clear[y] does remove function definitions and Clear[y[x]] fails.

Code:
In[1]:= y[x_] := 3 x

In[2]:= ?y

Out[2]= Global`y
Out[2]= y[x_]:=3 x

In[3]:= Clear[y]

In[4]:= ?y

Out[4]= Global`y

In[5]:= y[x] := 3 x

In[6]:= Clear[y[x]]

Clear::ssym: y[x] is not a symbol or a string. >>

As the IT Guy says, "Have you tried turning it off and turning it back on again" (possibly trying a ?y before anything else and then just entering that DSolve line and nothing else)?
 
Bill Simpson said:
Clear[y] does remove function definitions and Clear[y[x]] fails.

You're right, I'm wrong. Apologies for the mis-information.
 
Bill Simpson said:
Clear[y] does remove function definitions and Clear[y[x]] fails.

Code:
In[3]:= Clear[y]

In[4]:= ?y

Out[4]= Global`y[/QUOTE]
Clear clearly didn't work quite as advertised there. clear[y] puts y in limbo rather than removing it. Remove might be better here than clear.
 
Code:
In[1]:= y[x_] := E^x

In[2]:= DSolve[y'[x] == y[x], y[x], x]

Out[2]= During evaluation of In[2]:= DSolve::dsfun: E^x cannot be used as a function. >>
Out[2]= DSolve[True, E^x, x]

In[3]:= Clear[y]

In[4]:= DSolve[y'[x] == y[x], y[x], x]

Out[4]= {{y[x] -> E^x C[1]}}
 
I've always wanted to see a great example where Clear wasn't enough and Remove was necessary, not just some weird trick, but really interesting use that could be learned from and applied in useful ways in the future.
 
  • #10
Ah, I didn't know there was a remove function! Hopefully that works, I'll try it momentarily. And yes, I restarted Mathematica several times and it persisted.

I tried it in the document where it wasn't working, and it didn't work. However i downlaoded another copy of the assignment and it worked with y[x]! Strange.
 
Last edited:

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 7 ·
Replies
7
Views
6K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K