help with bvp4c error

Hello! I am trying to solve a system of four coupled differential equation with two-point boundary conditions. I am getting errors and i am new to this, so i dont understand. Please help me fix it.
function proca_star
clear;
clc;
format long;
infinity = 10;
w=0.817;
x_init=1e-5:0.01:infinity;
global phi_c
for phi_c=[0.394 0.394 0 0]
%solinit = bvpinit(linspace(1e-5,infinity,1000),[1 1 phi_c 0],omega);
solinit = bvpinit(x_init,[1 1 phi_c 0],w);
options = bvpset('stats','on','RelTol',1e-6);
%condition=true;
%while condition
sol = bvp4c(@bsode,@bsbc,solinit,options);
%condition = sol.stats.maxerr >= 1e-5;
%end
r_data = sol.x;
f = sol.y;
% Plotting the results
figure(1)
plot(r_data, f(1,:));
axis([0 infinity 0 1.5]);
title('\sigma vs r')
xlabel('r')
ylabel('\sigma')
figure(2)
plot(r_data, f(2,:));
axis([0 infinity -0.5 1]);
title('f vs r')
xlabel('r')
ylabel('f')
figure(3)
plot(r_data, f(3,:));
axis([0 infinity 0 1]);
title('m vs r')
xlabel('r')
ylabel('m')
figure(4)
plot(r_data, f(4,:));
axis([0 infinity -0.5 1.5]);
title('g vs r')
xlabel('r')
ylabel('g')
end
end
% --------------------------------------------------------------------------
function dfdr = bsode(r, y)
w = 0.817;
N = 1 - 2 * y(3) / r;
dfdr = [4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2))
w * y(4) - 0.745 * y(1)^2 * N * y(4) / w
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)))
r^2 * y(2) * w / (y(1)^2 * N^2) - 2 * y(4)];
end
% --------------------------------------------------------------------------
function res = bsbc(ya, yb)
global phi_c
res = [ya(1) - 0.394
ya(2) - 0.394
ya(3) - 0
ya(4) - 0
yb(1) - 1
yb(2) - 0
yb(3) - 0.745
yb(4) - 0];
end
Here is the error shown:
Error using proca_star>bsode
Too many input arguments.
Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in proca_star (line 22)
sol = bvp4c(@bsode,@bsbc,solinit,options);

回答(1 个)

Torsten
Torsten 2024-7-16
编辑:Torsten 2024-7-16
Use
solinit = bvpinit(x_init,[1 1 phi_c 0]);
instead of
solinit = bvpinit(x_init,[1 1 phi_c 0],w);
Why did you use the w-parameter in he call to "bvpinit" ?
And supply only 4 instead of 8 boundary conditions.

6 个评论

T
T 2024-7-16
编辑:T 2024-7-16
okay i have removed w from that part.
how do i write four boundary conditions. i have mentioned the initial point conditions under phi_c. my boundary conditions are : \sigma(0)= 0.394, f(0)=0.394, m(0)=0, g(0)=0 and \sigma(10)=1, f(10)= 0, m(10)=0.745, g(10)=0
Torsten
Torsten 2024-7-16
编辑:Torsten 2024-7-16
A first-order ODE needs one boundary condition. According to your code, you have four first-order ODEs - thus you need four boundary conditions.
So choose 4 out of the 8 you posted or do whatever makes the number of boundary conditions 4 instead of 8.
i think i have to input the conditions at r=0 separately and r=10 separately. can you please tell me on how do i proceed with that?
You cannot keep all eight conditions fixed. According to the graphics in your other post about the same problem, it seems that the four conditions g(0) = m(0) = 0, f(inf) = 0 and sigma(inf) = 1 are the relevant ones the solution must satisfy. But I might be wrong.
is there a way i can put the four initial conditions and four surface conditions separately? perhaps shooting method?
Torsten
Torsten 2024-7-17
编辑:Torsten 2024-7-17
Initial conditions for "bvp4c" are only used as starting conditions for the solver iterations of the solution. They are not kept constant in any point of the domain and can be far different in the final solution. They are specified in the "guess" function or - if you choose them to be constant - in the call to "bvpinit".
Boundary conditions for "bvp4c" as defined in "bsbc". These are the relevant settings to make the solution unique and are respected during the iteration process and in the final solution.
So I don't understand your wording about initial conditions and surface/boundary conditions. They are always set separately, and only the boundary conditions set are really relevant for the final solution.
Maybe you think about how the shooting methods works: you have to guess 4 initial conditions and correct some of them depending on the end conditions specified. But also with the shooting method, you only specify 4 conditions that have to be fulfilled in the final solution - the other conditions are adequately adjusted.

请先登录,再进行评论。

类别

产品

版本

R2024a

提问:

T
T
2024-7-16

编辑:

2024-7-17

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by