help with bvp4c error
1 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
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 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Boundary Value Problems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!