Can matlab solve a system of more than two PDEs numerically? - matlab

I know that MATLAB can solve a system of 2 coupled PDEs using pdex4, however is there something similar that can solve a system of more coupled PDEs, say 6? The bigger system has the same structure (dependence on partial derivatives, boundary conditions, type of initial condition etc) as the system of 2 equations.
Thanks.

With the FEATool Matlab FEM toolbox you can set up and solve an arbitrary number of coupled PDEs.

The function pdefun (that you pass as an input to pdepe) defines your system of equations and has the general form,
[c,f,s] = pdefun(x,t,u,dudx)
c, f, and s are coefficients in the PDE (see Eq. 1-3 here). They can be column vectors to allow for any number of coupled equations. In the pdex4 example these vectors have 2 elements; in your case they would have 6.

MATLABs Partial Differential Equation Toolbox allows you to solve systems of multiple equations. For coupling of source terms, you can solve the initial PDE for the source, then use that as an input for a second PDE model which will give the final results. More info can be found here

Related

How to solve this system of differential equations in matlab?

My task is to model a certain physical problem and use matlab to solve it's differential equations. I made the model but it seems far more complex than what I've learned so far so I have no idea how to solve this.
The black color means it's a constant
I assume that by "solve" you seek a closed form solution of the form x(t) = ..., z(t) = ... Unforunately, it's very likely you cannot solve this system of differential equations. Only very specific canonical systems actually have a closed-form solution, and they are the most simple (few terms and dependent variables). See Wikipedia's entry for Ordinary Differential Equations, in particular the section Summary of exact solutions.
Nevertheless, the procedure for attempting to solve with Matlab's Symbolic Math Toolbox is described here.
If instead you were asking for numerical integration, then I will give you some pointers, but you must carry out the math:
Convert the second order system to a first order system by using a substitution w(t) = dx/dt, allowing you to replace the d2x/dt2 term by dw/dt. Example here.
Read the documentation for ode15i and implement your transformed model as an implicit differential equation system.
N.B. You must supply numerical values for your constants.

What kind of numerical method does 'pdepe' (MATLAB function's) use?

I'm using the MATLAB's function 'pdepe' to solve a problem with some partial differential equations, a parabolic one.
I need to know the kind of numerical method that function uses, 'cause I have to notify this in a report.
The description of the function in MathWorks is "Solve initial-boundary value problems for systems of parabolic and elliptic PDEs in one space variable and time". Is it a finite difference method?
Thanks for helping me.
Taken from the Matlab 2016b documentation for pdepe:
The time integration is done with ode15s. pdepe exploits the
capabilities of ode15s for solving the differential-algebraic
equations that arise when Equation 1-3 contains elliptic equations,
and for handling Jacobians with a specified sparsity pattern.
Also, from the ode15s documentation:
ode15s is a variable-step, variable-order (VSVO) solver based on the
numerical differentiation formulas (NDFs) of orders 1 to 5.
Optionally, it can use the backward differentiation formulas (BDFs,
also known as Gear's method) that are usually less efficient
As indicated by Alessandro Trigilio, ode15s is used to advance the solution forward in time. Exactly what the function is advancing in time is a semi-discrete, second-order Galerkin formulation for non-singular problems or a semi-discrete, second-order Petrov-Galerkin formulation for singular problems (polar or spherical meshes that include the origin). As such, the spatial discretization is finite element in nature.

What is the best method of solving a large system of constrained linear and non linear equations in matlab?

Solving system of constrained linear and non-linear equations in MATLAB
I'm solving a FEM problem in MATLAB with use of the direct stiffness method. The problem is now formulated as a system of non linear equations:
KU=F or CF=U with C = K^{-1}.
the problem is formulated in 3-Dd and has over 200 nodes. The model is used as a deformation estimator, the force is always the input and the deformation output. So there are a lot of linear equations. Now this problem needs to be extended, 2 types of constraints need to be implemented. Some of the nodes have to be constrained so that they only can move in a circular motion around a given point. And some of the nodes have to be bound with a maximum amount of deformation.
in total there will hundreds of equations of the form equations of the form:
a_1 X(1) + a_2 X(2) + ... - F(1) = 0
about 10 equality constraints of a nonlinear form like (could also be a sinusoid):
X(1)^2 + X(2)^2 = L
and 10 inequality constraints of the form:
X(1) < 30\pi/180
What is the best method to solve a nonlinear system of equations with constraints of this type simultaneously? Is it possible to use fsolve? Or fmincon? I've been looking into solvers but I can't find a solid conclusion on what solver can handle all these equation types at once and what would be most efficient in terms of computation time.
Without knowing too much of your type of problem, you should have a look on more specific mathematical-optimisation tools, where you can write your "similar" constraints only once, decide to which dimensions do they apply, and the language then expand them accordingly.
For the solver-engine for non-linear problem I would suggest IPOPT. It's free and it has very good performances.
For the modelling tools, you have the choice between dedicated mathematical-optimisation packages, like GAMS or AMPL, or - more and more common nowadays - libraries that extend general-purposes languages into the domain of mathematical optimisation (in this second case I would suggest Pyomo for Python or JuML for Julia)

Dymola solving stationary equation systems for Media-Model

I'm building a Media-Library in Dymola similar to Helmholtz-Media but for Ammonia+Water, a mixture.
You get a lot of not explicitly solvable equations.
Because of the structure of the Media and Fluid libraries in Modelica I need to be able to get my thermodynamic state from p, h and x. The state-vector consists of d, T, and x.
This is a simple example how to get the state-vector:
model getState_phX
parameter AbsolutePressure p = 500000 "pressure";
parameter SpecificEnthalpy h = 2500000 "enthalpy";
parameter SI.MassFraction x = 0.7 "mole fraction of amonia";
parameter Real[2] start = getStart_Td_phx(p,h,xL);
output ThermodynamicState state(d(start=start[2]),T(start=start[1]),X={(1 - xL),xL});
DerivateFull f = Derivates(state);
equation
p = (1 + f.delta*f.phirdelta)*R*state.T*state.d/molarMass(state);
h = state.T*R*(1 + f.delta*f.phirdelta + f.tau*f.phirtau + f.tau0*f.phi0tau0)/molarMass(state);
end getState_phX;
Please don't mind the parts of the equations. They consist of many parts (sums and log) dependent on the state-vector.
This is solved by the solver in Dymola with good start values.
But I don't really need all of the 'time-dependent' solving capabilities of Dassl.
Are there build in libraries for solving such stationary equation systems without the solver?
Is it possible to make a Function out of this Model using these?
I know I could write a simple solver by hand but for other parts of the Media-Model (VLE) I need highly reliable stationary solver too (but with 4 nonlinear independent equations)
Please tell me if I didn't explain myself clearly. Thank you for the help.
The basis of your fluid properties library is a forward part, that is the actual Helmholtz energy equation of state (EoS). It takes d,T,X as input. That part is more or less straigthforward to implement.
If you want to specify the thermodynamic state using p,h,X or if you want to find the equilibrium between multiple phases, you will usually set up a system of resdiual functions and try to find the root of your system of equations using some iterative procedures. Span (2000) writes
"the formulation of reliable iterative procedures [for root finding]
is often the most crucial problem when setting up program packages for
the evaluation of equations of state".
Re-using existing solvers has advantages and disadvantages, they are usually very well tested, writing them takes a lot of effort, but if you write your own solver, you have more control about what it does. As far as I know, Dassl has various strength, but solving that kind of equations is not its original objective.
Olson, Tummescheit and Elmqvist (2005) tried to use the Dymola solver to find the VLE, see section 3.2 of the linked pdf. Sounds like it works, but not very reliable.
The MSL already includes a non-linear solver, based on the Brent algorithm, which works with one unknown only, see Modelica.Math.Nolinear.solveOneNonlinearEquation. You could, if you want, add additional generic solvers.
Before writing your own solver, you should get in touch with the developers of the Modelica.Media interface (it will be extended in future versions of the MSL to include multi-component, multi-phase mixtures) and also consider re-using existing fluid properties libraries like RefProp, CoolProp, FluidProp or MultiFlash, to name just a few.

Using a non-matlab ODE simulator to run a model created in matlab/simbiology - how to represent "repeated assignment" rules?

I am using non-matlab ODE simulation software to reproduce a model that was created with the simbiology toolbox in matlab.
One issue is the representation of repeated assignments. Is it possible to re-express repeated assignments in a way that they can be simulated in a standard Runge Kutta (or other iterative method) which only supports ODE systems? Or is it impossible re-express a model with repeated assignments as a system of ODEs?
It is possible. In SimBiology, for most repeated assignments, you can take the assignment statement
x = y + z
and think of it as
dx/dt = dy/dt + dz/dt
and you could integrate that state. That may be the simplest way to implement what you have, keeping in mind that if you have some more complicated function that makes the assignment, you will have to carryout the chain rule correctly.
This is not how repeated assignments are handled in SimBiology. When putting together the solvers in SimBiology we can manipulate both the right hand side of the system of differential equations and the solution of the states. We implement something a bit better from the perspective of ODE solution accuracy and speed of solution, but without knowing more about your solver, I can't advise you on how to proceed.
--Andrew
(one of the SimBiology devs)