How Can I Fix My DSolve Output to Work as a Function?

In summary, the conversation discusses a problem with defining a function called uEven to solve a given ODE. The solution is not working as a typical function and the user is seeking help in fixing it so that it can be differentiated and integrated without copy-pasting. The desired outcome is for the solution to adapt to different input constants. The solution involves using the syntax "uEven[x_, b_, l_, \[Alpha]_, L_] := ..." to properly define uEven as a function.
  • #1
member 428835
Hi PF!

The following is a simple ODE I'm solving via DSolve. However, the solution, which I call uEven, does not work as a typical function. Note the last two lines are different. Does anyone know how to fix this, so that I can differentiate and integrate the output of this ODE without copy-pasting?

Ideally I'd like the solution to adapt to different input constants shown at the top. Any help much appreciated!

Code:
L = 0.005;  (* HALF CHANNEL LENGTH  (m)       *)
\[Sigma] = 0.07;    (* \
SURFACE TENSION      (N / m)   *)
\[Rho] = 1000; (* LIQUID \
DENSITY       (kg / m^3) *)
g = 9.8;     (* GRAVITY ACCELERATION (m / \
s^2)  *)
\[Alpha] = 
 70 \[Pi]/180; (* STATIC CONTACT ANGLE (rad)     *)
l = \
Sqrt[\[Sigma]/(\[Rho] g)]; (* CAPILLARY LENGTH SCALE (m) *)
b = (\
\[Rho] g l^2)/\[Sigma]; (* BOND NUMBER *)
\[CapitalGamma][x_, 
  l_, \[Alpha]_, L_] := 
 l Cot[\[Alpha]] Exp[L ( x - 1)/l](* EQUILIBRIUM HEIGHT (m) *)

uEven[x, b, l, \[Alpha], L] = 
  y[x] /. First@
    DSolve[{-y''[
          x] + (b Cos[\[Alpha]] - \[CapitalGamma][x, l, \[Alpha], 
            L]^2) y[x] == 0, y'[0] == 0}, y, x];
uEven[x, b, l, \[Alpha], L]
uEven[y, b, l, \[Alpha], L]
 
Physics news on Phys.org
  • #2
You are not defining uEven as a function, you are just defining it as a single symbol. You want to use the following syntax instead:

uEven[x_, b_, l_, \[Alpha]_, L_] := ...
 
  • Like
Likes member 428835
  • #3
Dale said:
You are not defining uEven as a function, you are just defining it as a single symbol. You want to use the following syntax instead:

uEven[x_, b_, l_, \[Alpha]_, L_] := ...
Must've been real late, can't believe I missed this. Thanks!
 
  • Like
Likes Dale

FAQ: How Can I Fix My DSolve Output to Work as a Function?

What is the purpose of using DSolve to obtain the output as a function?

The purpose of using DSolve is to solve differential equations and obtain a general solution in the form of a function. This allows us to easily evaluate the solution for different values of the independent variables and obtain a more comprehensive understanding of the behavior of the system.

How can I specify the initial or boundary conditions when using DSolve to obtain the output as a function?

To specify initial or boundary conditions, you can use the optional argument "InitialConditions" in the DSolve function. This argument takes a list of equations that represent the given conditions for the dependent and independent variables.

Can I use DSolve to obtain the output as a function for systems of differential equations?

Yes, DSolve can be used to solve systems of differential equations and obtain the output as a function. The system of equations can be specified using a list of equations, and the output will be a list of functions corresponding to the dependent variables.

How accurate is the output obtained from DSolve as a function?

The accuracy of the output obtained from DSolve as a function depends on the accuracy of the input equations and conditions. DSolve uses symbolic methods to solve the equations, so the results may not always be exact. However, the output can be made more accurate by using higher precision numbers and checking for any simplifications in the solution.

Are there any limitations to using DSolve to obtain the output as a function?

Yes, there are limitations to using DSolve to obtain the output as a function. It may not be able to solve all types of differential equations, especially those with complex or nonlinear terms. In such cases, numerical methods may be more suitable for obtaining the solution.

Similar threads

Replies
7
Views
2K
Replies
1
Views
1K
Replies
6
Views
2K
Replies
6
Views
6K
Back
Top