Message Boards Message Boards

0
|
5333 Views
|
9 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Avoid DSolve error for the following differential equation?

I keep getting an error with DSolve that I do not understand. It finds the solution then says it can't use it. Please see the attached file.

Attachments:
POSTED BY: Orest Gogosha
9 Replies

Thank you for clarifying the use of ClearAll. What happens is that when DSolve finds a solution, which has happened when I don't use units, it asks if you want to convert that solution into a function. Once you pick that option, you get a function. However, if you now reevaluate the notebook for some reason, you get the error. I don't use Mathematica much. Although it's been a long time, I can still solve simple ODEs by hand. What I'm trying to do is get my students interested in making programming an integral part of their way of doing scientific and engineering computations. It's hard to do when a program has so many idiosyncrasies.

POSTED BY: Orest Gogosha

I am not concerned about the "Not all solutions warning. I understand that. I don't understand the cannot be used as a function." It comes and goes. Please compare the attached files.

Thanks,

GOGO

POSTED BY: Orest Gogosha
Anonymous User
Anonymous User
Posted 4 years ago

You have initial conditions x[0] == 1, x'[0] == 0.

You'll find for ODE sometimes you'll get a solution if you omit the IC where with the IC Mathematica yields no solution. (But with the full general solution you can solve constants for those IC using Solve having the (general in this case) solution.)

This may be because Mathematica will show nothing rather than give you an answer that is "vague" - so if you inadvertently give IC that could allow more than one solution: mm may show you nothing.

You should substitute the solution you get, and in general and ask if there are singular solutions (points outside the general solution) or other "gotchas". For homework of course, you'll likely set that aside.

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 4 years ago

NSolve::ifun: Inverse functions are being used by NSolve, so some solutions may not be found; use Reduce for complete solution information.

This means what is says. however: remember that PDE may have functions as arbitrary while ODE constants as arbitrary, and moreso that some ODE you hope to find "a solution" while others you can say "are likely general" while other (by definition or by analysis) are certainly general (all solutions).

My point is before worrying whether your inverse is all solutions ask if you had any chance of finding all solutions.

Use of numbers like ".001" are a bad idea for DSolve - use arbitrary precision numbers (fractions). also - nsolve is not needed for the simple harmonic motion equation (mm can do it).

x''[t] + x[t] == c

is a linear differential equation of order two, non-homogenous

You can find an equation showing all solutions of it by knowing your theorems tell you that is the case . yp+yc, yc can be found using undetermined coefficients.

Your characteristic equation is (m^2+1) will involve imaginary number, which is parlayed into sin/cos function in a sensible way for use with wave equations. You may have a table of simple harmonic equations with the solution outcomes in your book (undamped or damped and unforced or not) so you can plug in constants to known solutions (tenenbaum).

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 4 years ago

DSolve::dsfun: -0.0102625+0.110263 Cos[22.3607 t] cannot be used as a function.

that means you have a typo, you've tried to use the above as a function - just like the message says. your "unkown function" (ie, y''[x]) has to have form f[u], f'[u], ... which is likely what you intended. (obviously u might have substitution, see help how and where such can be used). if you look again, compare it to Help examples, you'll see the simple typo

POSTED BY: Anonymous User

Something interesting is going on. I restarted windows. The results are attached. The solution with units still doesn't work, but others do.

POSTED BY: Orest Gogosha
Posted 4 years ago

To try to be helpful and to sometimes speed things up Mathematica remembers past assignments and silently uses those assignments later. I am guessing this explains part of what you are seeing.

Sometimes you want it to forget a prior assignment. Thus you have used

ClearAll[all]

What that does is completely forget any value that you might have previously assigned to a variable called "all". From the documentation, But, at least in the code you have shown, there is no variable called "all" and no contents have been assigned to it and so that does nothing. In particular it doesn't forget any prior assignments to x, t, or anything else.

You can even try a little experiment like this

x=3;
all=4;
Print[x]
Print[all]
ClearAll[all]
Print[x]
Print[all]

I suspect what you might want to use instead is

ClearAll["Global`*"]

which tells Mathematica to look in the global database of assignments and forget everything in there. You can find that in the documentation for ClearAll if you look carefully for that.

Even without making that change to your code, it may be impossible to exactly reproduce all the steps you have previously done and get it to give you the same error message for exactly the same reason. If you were able to do that and could be certain the error message was coming up for exactly the same reason then you could try making that change to ClearAll and reproducing those steps yet again and see if the error did go away.

It might be possible to just restart Mathematica, without needing to restart your entire computer. Restarting Mathematica should forget prior assignments, unless you have put some assignments into the initialization code for Mathematica.

See if you can use this information to get to a place where you can be really confident about what it is doing. That is probably essential for further productive learning and work.

None of this even tries to address using units in DSolve, that is an entirely different topic.

POSTED BY: Bill Nelson

Thank you for the quick response. I tried your suggestion. Please see the attached file.

GOGO

Attachments:
POSTED BY: Orest Gogosha
Posted 4 years ago

One way of getting around that error is

ClearAll[all];
mice=50.*10^-3;
thetaslope=30.*Pi/180;
kspring=25.;
xspring=100.*10^-3;
g=-9.8;
DSolve[{mice*x''[t]+kspring*x[t]==thetaslope*mice*g,x[0]==.1,x'[0]==0},x[t],t]

which returns

{{x[t]->-0.0102625+0.110263 Cos[22.3607 t]}}

Check the documentation on ClearAll because you might also be using that incorrectly.

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

Group Abstract Group Abstract