Error messages using bvp4c
이전 댓글 표시
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
Jan
2021년 3월 20일
If you post the text as text and not as screenshot, the readers can use it by copy&paste to create an answer.
답변 (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
카테고리
도움말 센터 및 File Exchange에서 Boundary Value Problems에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!