Error messages using bvp4c
Show older comments
I continually am getting the same error messages for a bvp4c problem. I am using exactly the format from a Matlab provided example:
I saved these functions:
function dfdeta = fsode(eta,f)
dfdeta = [ f(2)
f(3)
-f(1)*f(3) - 1*(1 - f(2)^2) ];
end
function res = fsbc (f0,finf)
res = [f0(1)
f0(2)
finf(2) -1];
end
Then tried to apply:
infinity = 3;
maxinfinity = 6;
solinit = bvpinit(linspace(0,infinity,5),[0 0 1]);
sol=bvp4c(@fsode,@fsbc,solinit);
I get the follow error messages:

1 Comment
Jan
on 20 Mar 2021
If you post the text as text and not as screenshot, the readers can use it by copy&paste to create an answer.
Answers (1)
res = [f0(1)
f0(2)
finf(2) -1]
The 1st and 2nd row contain 1 element, the 3rd row contains 2 elements. Be careful with the smart methods of Matlab, which allows you to omit commans and semicolons. The unary minus has no space on the right side, but the minus operator has one, if there is a space on the left. Tricky!
[1 2] % [1, 2]
[1 -2] % [1, -2]
[1 - 2] % [-1] !!!
Although it is convenient to omit the commas and semicolons, this is very susceptible for the distribution of spaces and therefore a bad programming style. I strongly recommend to write clean and clear code and not to use the lazy omitting. Use spaces around operators and omit the space on the right only for the unary minus operator:
res = [f0(1); ...
f0(2); ...
finf(2) - 1];
% ^ a space
Categories
Find more on Boundary Value Problems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!