0

I need to solve two differential equations of the first order, with one unknown parameter in each equation (m_0 and m1 are unknown parameters), and I have four boundary conditions. My function for guessing solution is pinit:

function pinit = mat4init(z)
pinit = [ 0.65.*cos(z)
          0.65.*cos(z) ];
end

I also have function for boundary condtions mat4bc, where I put boundary conditions for the first equation (with index 1) and after that for the second equation:

   function res = mat4bc(pa, pb)
      res = [ pa(1,:)-8
            pb(1,:)-1
            pa(2,:)
            pb(2,:) ];
   end

I am making assumption for unknown parameters m0, and m1 with values 2 and 1. Together with other values in matrix4ode function are given differential equations :

function dpdz = matrix4ode(z, p)

m0 = 2;
m1 = 1;
z = linspace(0,pi,10);
ri = 0.7;
R = ri - z .* (ri - 1);
beta = 1;

dpdz = zeros(2, size(z,2));
dpdz(1,:) =   - 32 .* beta .* m0 ./ (R .^ 4 .* p(1,:));
dpdz(2,:) = -( - 8 .* dpdz(1,:) ./ R - dpdz(1,:) .* p(2,:) - 32 .* beta .* m1 ./ R .^ 4 ) ./ p(1,:);
end

And I am using bvpinit:

solinit = bvpinit(linspace(0,pi,10),@mat4init , [2 1]);

and after that calling bvp4c with code:

m0 = 2;
m1 = 1;
z = linspace(0,pi,10);
ri = 0.7;
R = ri - z .* (ri - 1);
beta = 1;
sol = bvp4c(@matrix4ode,@mat4bc,solinit);

and I got error:

Error using matrix4ode
Too many input arguments.

Error in bvparguments (line 105)
    testODE = ode(x1,y1,odeExtras{:});

Error in bvp4c (line 130)
    bvparguments(solver_name,ode,bc,solinit,options,varargin);

How when I have not additional input arguments in matrix4ode function? What should I do? Here is my code

iviviviviv
  • 21
  • 8
  • You have two equations but 4 boundary conditions? And you overwrite the input `z` in `matrix4ode`? `matrix4ode` should return a 2x1 column vector. – David Apr 01 '20 at 22:43
  • Yes, I have two equations, 4 boundary conditions and two unknown parameters, so that should be closed system, isn`t it? I wrote that in my question. What should I do for z in matrix4ode? And how to tell matrix4xode to return 2x1 column vector? I did it according to Matlab help. – iviviviviv Apr 02 '20 at 14:01
  • You have two first order ODEs. You can apply 2 boundary conditions, one for each ODE. You can't specify two boundary conditions for a first order ODE. – David Apr 02 '20 at 22:13
  • Yes, but I have two unknown parameters, that should cover additional two conditions. – iviviviviv Apr 03 '20 at 07:21

1 Answers1

0

Matlab has, unlike python scipy's solve_bvp, no provision for variable parameters. You need to add them artificially as state variables that have derivative zero. This would give you (removing some crufty constructs)

function dpdz = matrix4ode(z, p)

  m0 = p(3);
  m1 = p(4);
  ri = 0.7;
  R = ri - z .* (ri - 1);
  beta = 1;

  dpdz = zeros(4,1);
  dpdz(1) = - 32 .* beta .* m0 ./ (R .^ 4 .* p(1));
  dpdz(2) = -( - 8 .* dpdz(1) ./ R - dpdz(1) .* p(2) - 32 .* beta .* m1 ./ R .^ 4 ) ./ p(1);
end
Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • I run code with your suggestion and with changes in function mat4bc, where I put that boundary conditions are: pa(1)-8; pb(1)-1; pa(2); pb(2), but I still have the same error: Error using matrix4ode Too many input arguments. – iviviviviv Apr 02 '20 at 17:51
  • You would also have to adapt `mat4init` to have the guessed values in the 3rt and 4th component. But that should have led to a different error. Remote debugging does not work here, it seems to be a more global error. If you do not have an epiphany in the short term, you could try to *add* your complete code to the question (or indicate for the existing code if it is the content of separate .m files if they are unchanged). – Lutz Lehmann Apr 02 '20 at 18:04
  • I added my code at the end of my question, I did not changed only mat4bc.m - boundary conditions, but with this added version I still have the same error: To many input arguments – iviviviviv Apr 02 '20 at 18:32
  • I changed the line `dpdz = zeros(4,1);` so that it explicitly gives a column vector. Matlab is sometimes strange where it does conversion and where it extends the objects to fit. – Lutz Lehmann Apr 02 '20 at 19:24
  • Ok, I tried with that, but I still have the same error: To many input arguments – iviviviviv Apr 02 '20 at 20:14