I have a problem in solving nonlinear parabolic pde of following form.
(consider u_x as differentiation of u w.r.t. x)
U(1)_t = a1(U(1),x)*U(2)_t + b1(U(1),x,U(3)) = ( D1(x,U(1))*U(1)_x )_x + c1( U(1), U(3))*U(1)_x ---(1)
and its coupled equation
U(3)_t = a2(U(1),U(3))*U(2)_t + b2(U(1),x,U(3)) = ( D3*U(3)_x )_x ---(2)
as you can see U(1), U(2), U(3) are there with only two PDE. That is because U(2) is not function of x and has its own pde as
U(2)_t = (1/r)( D2(U(2))*U(2)_r )_r ---(3)
Now (3) is standalone solvable. I solved it with pdepe in MATLAB. Now I need to put value of U(2)_t in (1)&(2) then solve them, which I couldn't do in pdepe.
So this is my question. Is there any way that after solving (3), value of U(2)_t could be imported in (1)&(2) and solve them simultaneously. Alternatively, is there any way that I can incoporate (3) directly in differential form in (1)&(2) and solve resulting coupled system in MATLAB. Thanks in Advance.
You'll have to linearize and do an iterative solution. Newton-Raphson is usually the preferred method, although some people like BFGS.
I don't know how you formulate your PDEs. Finite difference, finite element, boundary element, or something else? Just posting the PDEs doesn't tell me enough.
Related
I have the following equation system (click to see picture)
, and would like to solve for X(t), Y(t), Z(t), hopefully using Octave/Matlab, which I'm familiar with, but I would not mind solving it by any other means necessary.
Now, Fsolve is useful for regular equation systems, and Ode45, Lsode are useful for differential equations. But, what about this particular system? Note that the differential equation at the bottom contains not only Y, but, also, both X and Z, and those are dependent on the two non-differential equations above.
To be honest, I'm not quite sure how to approach a basic code to solve this system, and after spending some time thinking, I decided to ask for help. I really appreciate any guidance to solve this problem somewhat efficiently, if it is even possible. Almost any reply would be of some use to me right now.
If you know y, you can solve for x, and this even unconditionally as the second equation in monotonous in x
x = fsolve(#(x) y^2-1413.7*x-1095.2*cos(x)+2169, 0)
Then once you know x, you can solve for z using the known inverse cosine
z = acos(0.20978-cos(x))
This may actually fail to give a result if cos(x) comes close to -1. One can artificially cut out that error, introducing a possibly wrong solution
z = acos(min(1,0.20978-cos(x)))
For simplicity, assemble these operations in a helper function
function [x,z] = solve_xz(y)
x = fsolve(#(x) y^2-1413.7*x-1095.2*cos(x)+2169, 0);
z = acos(min(1,0.20978-cos(x)));
end
Now use that to get the ODE for y
function dy = ode_y(t,y)
[x,z] = solve_xz(y(1));
dy = [ y(2); y(3); 6666.6667*(z-x)-333.3333*y(1)-33.3333*y(2)-5*y(3) ];
end
and apply the ODE solver of your choice. It is quite likely that the system is stiff, so ode45 might not be the best solver.
I am trying to solve an optimization problem where the given objective function is to minimize
norm(R - R*)
where R is obtained by solving a boundary value problem (BVP) and `R* is a known value.
For example:
R = (p1 + p2*p3);
The BVP is given by
p1dot = p2 + p3 + x1;
p2dot = x2 + p1*p2;
p3dot = x3 + p1*p2*p3;
where x1, x2 and x3 are the optimized variables.
I am trying to solve this in MATLAB using fmincon where the BVP is solved in the objective function at every guess by the solver to estimate norm(R-R*).
EDIT 1 : I have a non linear inequality constraint which is a function of pi where i = 1,2,3. This is the reason for choosing fmincon
The issue I am facing is that during some guesses the BVP doesn't converge and the optimization stops. I guess the issue is some guess value to solve the BVP doesn't satisfy. If I give bounds to the variables then it solves the optimization problem. I am not really aware of the bounds on variables beforehand.
In order to overcome this I want to detect the guess when BVP is not solved, save them and force the optimization routine to not try values when it cannot be solved by going back to its previous guess. How do we implement this in fmincon routine?
EDIT 2 : I figured out the issue is with initial guess provided to the BVP solver. For smaller values of the optimization variables x this guess is good but when the magnitude of x increase this guess is not good enough.
Is there a way to update the solution of 'BVP' in the previous iteration as the initial guess for the next iteration in optimization. Intuitively this should fix it. Please let me know if there are some loop holes in this method.
I have a system that looks like
dn/dt=f(n,v)
dh/dt=g(h,v)
I want to solve this equation on the manifold F(v,n,h)=0, a nonlinear function in v. I tried to use something like v=fzero(#(x) F(x,n,h),0) to solve for the value of v on the manifold at each time step. But this is incredibly slow and ode15s (my system is a relaxation oscillator) fails to meet integration tolerance. How do I find solution to the ODE on the manifold defined by F(v,n,h)=0?
I find #LutzL's comment very helpful. It is possible to set up a DAE solver using ode15s.
Example: The "Solve Robertson Problem as Semi-Explicit Differential Algebraic Equations (DAEs)" section in https://www.mathworks.com/help/matlab/ref/ode15s.html
In my case, I would setup a matrix:
M=[zeros(1,3);0,1,0;0,0,1];
options = odeset('Mass',M,'RelTol',1e-5,'AbsTol',1e-6,'MaxStep',0.01);
y0=[v0,n0,h0];
[T,Y]=ode15s(#slow,[0 50],y0,options);
And slow is a function defined as:
function dy = slow(t,y)
v=y(1); n=y(2); h=y(3);
dy=zeros(3,1);
dy(1)=F(v,n,h);
dy(2)=f(n,v);
dy(3)=g(h,v);
end
One of the possible ways to solve this problem is to differentiate
the F(v,n,h)=0 equation:
Now we can obtain the ODE system
or
which can be solved in the usual way.
I am facing a problem in which I have to solve a system of equations:
\partial A \delta x = f(A) g(B)
\partial B \delta y = h(A) k(B)
in which f,g,h and k are some functions of A or B, and I have some initial conditions A(x=0) = a, B (y=0) = b. All previous variables are scalars.
I have solved this by making a little step in one variable and then integrating the other other equation for the whole range of the other variable (like an ode routine), then another step in the former variable and so on.
Do you have another idea more efficient? Is it possible to put one ode call running inside another call? Or perhaps there is something more elegant like combining both independent variables x and y, integrating a vector function and then undoing the change? I have the feeling that this could be done in some way.
Many thanks!
This looks to me like a partial differential equation system.
You can solve it with pdepe (here is the documentation) or you can discretize one dimension, let's say x, in Np points and have one y-equation on each point. You would complicate your system from 2 equations to Np, but turn it from PDE to ODE and therefore solvable with Matlab's ODEs.
I have a set of 4 PDEs:
du/dt + A(u) * du/dx = Q(u)
where,u is a matrix and contains:
u=[u1;u2;u3;u4]
and A is a 4*4 matrix. Q is 4*1. A and Q are function of u=[u1;u2;u3;u4].
But my questions are:
How can I solve above equation in MATLAB?
If I solved it by PDE functions of Matlab,can I convert it to a
simple function that is not used from ready functions of Matlab?
Is there any way that I calculate A and Q explicitly. I mean that in
every time step, I calculate A and Q from data of previous time step
and put new value in the equation that causes faster run of program?
PDEs require finite differences, finite elements, boundary elements, etc. You can also turn them into ODEs using transforms like Laplace, Fourier, etc. Solve those using ODE functions and then transform back. Neither one is trivial.
Your equation is a non-linear transient diffusion equation. It's a parabolic PDE.
The equation you posted has the additional difficulty of being non-linear, because both the A matrix and Q vector are functions of the independent variable q. You'll have to start by linearizing your equations. Solve for increments in u rather than u itself.
Once you've done that, discretize the du/dx term using finite differences, finite elements, or boundary elements. You should start with a weighted residual integral formulation.
You're almost done: Next to integrate w.r.t. time using the method of your choice.
It's not trivial.
Google found this: maybe it will help you.
http://www.mathworks.com/matlabcentral/fileexchange/3710-nonlinear-diffusion-toolbox