# Passing parameters in boundary value problem using BVP4C

8 ビュー (過去 30 日間)
Saeid 2019 年 12 月 1 日
Commented: Star Strider 2019 年 12 月 2 日
For a system of boundary value problems I need to pass a parameter as a coefficient. Let's assume that I have defined the problem as:
solinit = bvpinit(linspace(0,10,50),[0 10]);
sol = bvp4c(@twoode,@twobc,solinit,a);
x = linspace(0,4);
y = deval(sol,x);
function dydx = twoode(x,y,a)
dydx = [ y(2); -a*exp(-x)+x*exp(-x)];
end
function res = twobc(ya,yb,a)
res = [ya(1); yb(1)-10*exp(-10)];
end
Where a is the parameter, and my first try was to add a to all the functions involved, but I receive the "Not enough input arguments" error. Is there a way to include the parameter a in the problem?

#### 0 件のコメント

サインイン to comment.

### 採用された回答

Star Strider 2019 年 12 月 1 日
Define ‘a’ in your workspace, then use this bvp4c call:
sol = bvp4c(@(x,y)twoode(x,y,a),@(ya,yb)twobc(ya,yb,a),solinit);
You are passing the extra parameter correctly, however bvp4c does not need to know about it, so only show bvp4c the arguments it wants, thus:
@(x,y)twoode(x,y,a)
and:
@(ya,yb)twobc(ya,yb,a)
The anonymous function construction (that you wrote correctly) will pick up ‘a’ from your workspace and pass it to your functions.
With this change (and specifying ‘a’), your code ran without error with this bvp4c call when I tested it.

#### 2 件のコメント

Saeid 2019 年 12 月 2 日
Thanks, like always, your suggestions were a great help.
Star Strider 2019 年 12 月 2 日
As always, my pleasure!
I very much appreciate your compliment!

サインイン to comment.

Stephan 2019 年 12 月 1 日
See here: passing extra parameters. I suggest to either use the anonymous functions or the nested functions approach. Both is easy to apply.

#### 1 件のコメント

Saeid 2019 年 12 月 2 日
Thanks Stephan! I just did and it worked!

サインイン to comment.

サインイン してこの質問に回答します。

Translated by