Message Boards Message Boards

0
|
4395 Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Trying to solve a Simple system of differential equations

Posted 11 years ago
For some reason I'm getting an error which says 'Set::write:'

I am trying to solve 3 simple differential equations but am new to Mathematica, could anyone let me know what i'm doing wrong?

Many Thanks,

All are constants apart from Z,Pb and R

Will

 ClearAll["Global`*"];
 Pl = rho*g*Z[t] + Patm
 eqn1 = Pb[t] == rho*g*Z[t] + Patm + (2*gma)/R[t]
 eqn2 = R[t] == (((1 + x)*(rho*g*Z[t] + Patm)*r0^3)/Pb[t])^(1/3)
 eqn3 = Z'[t] = -(2/9)*(1/mu)*(R[t]^2)*(Pl - Pb[t]/(Rs*T))
 eqn = {Pb[t] == rho*g*Z[t] + Patm + (2*gma)/R[t] &&
     R[t] == (((1 + x)*(rho*g*Z[t] + Patm)*r0^3)/Pb[t])^(1/3) && 
     Z'[t] = -(2/9)*(1/mu)*(R[t]^2)*(Pl - Pb[t]/(Rs*T)) ,
   R[0] == 0.000025 && Z[0] == 1 }
(*eqns = {eqn1 && eqn2 &&  eqn3 , R[0] == 0.000025 && Z[0] == 1 }; *)
sol = NDSolve[eqn, {R[t], Pb[t], Z[t]}, t]
POSTED BY: Will Moss
5 Replies
Posted 11 years ago
Check out Mathematica's help section on the convention of solving equations with DSolve. Also take heed of Bill Simpson's post above. You'll have to get the structure correct before you solve the system. I would start with the simple example Bill gives, once you can solve that system, your system should be straightforward.
POSTED BY: Pat Mac
Posted 11 years ago
1. NDSolve requires that every symbol, other than the functions you are solving for and the independent variable, be assigned constant numeric values before evaluating NDSolve. Think of when you might have first been taught to numerically approximate differential equations and you were given y'[ t ] == q* y[ t ]. Now numerically approximate that EXCEPT I refuse to tell you what the value of q is.

2. If y is a function of t then every place you use y you must write that in the form y[ t ] (or y'[ t ] ), and not just y.

Both these are very common misunderstandings that come up again and again.

Unfortunately Mathematica does not yet provide blindingly clear error messages pointing out exactly where these rules have been broken and how the input needs to be changed.
POSTED BY: Bill Simpson
Posted 11 years ago
Here is an updated version of my script. I want to be able to plot z, and r.
Should I be using DSolve, NDSolve or something else?
I've tried to clear it up a bit

Thanks,

Will
POSTED BY: Will Moss
Posted 11 years ago
 ClearAll["Global`*"];
 
 (*Constants*)
 rho = 1000;
 g = 9.81;
 Patm = 100000;
 gma = 0.0728;
 mu = 0.0001;
 rs = 287;
T = 293.15;
Psat = 2399;

(*Variables*)
r0 = 25*(10^-6)

(*equations*)
eqn1 = Pb[t] == rho*g*z[t] + Patm + (2*gma)/r[t]
eqn2 = r[t] == (((1 + (Psat/Pb[t]))*(rho*g*z[t] + Patm)*r0^3)/Pb[t])^(1/3)
eqn3 = z'[t] == -(2/9)*(1/mu)*(r[t]^2)*(Pl - Pb[t]/(rs*T))

eqn = {eqn1 && eqn2 &&  eqn3 , r[0] == 0.000025 && z[0] == 1 }

sol = DSolve[eqn, {r[t], Pb[t], z[t]}, t]
POSTED BY: Will Moss
Posted 11 years ago
Check your equation for Z... You are using a set ( = ) instead of an ( == ). Also be careful about capital letters such as R or Z, Mathematica uses this naming conventions for several functions or variables (i.e. D -> derivative), I would avoid Capital one letter names for variables entirely. There are some more issues here, that will be easier to see if you clean up the code a bit.
POSTED BY: Pat Mac
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