Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.4K 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
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
Posted 6 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
Anonymous User
Anonymous User
Posted 6 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 6 years ago
POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 6 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

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

GOGO

Attachments:
POSTED BY: Orest Gogosha
Posted 6 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