Hello everyone,
Could someone help me to understand why I got this error while running my script :
>> shoot4nl
Not enough input arguments.
My script is the following :
function shoot4nl
% Shooting method for nonlinear 4th-order boundary
% value problem
global XSTART XSTOP H % Make these params. global.
XSTART = 0; XSTOP = 1; % Range of integration.
H = 0.1; % Step size.
freq = 1; % Frequency of printout.
u = [-1 1]; % Trial values of u(1)
% and u(2).
x = XSTART;
u = newtonRaphson2(@residual,u);
[xSol,ySol] = runKut5(@dEqs,x,inCond(u),XSTOP,H);
printSol(xSol,ySol,freq)
function F = dEqs(x,y) % Differential equations.
F = zeros(1,4);
F(1) = y(2); F(2) = y(3); F(3) = y(4);
if x < 10.0e-4; F(4) = -12*y(2)*y(1)^2;
else; F(4) = -4*(y(1)^3)/x;
end
function y = inCond(u) % Initial conditions; u(1)
y = [0 0 u(1) u(2)]; % and u(2) are unknowns.
function r = residual(u) % Bounday residuals.
global XSTART XSTOP H
r = zeros(length(u),1);
x = XSTART;
[xSol,ySol] = runKut5(@dEqs,x,inCond(u),XSTOP,H);
lastRow = size(ySol,1);
r(1) = ySol(lastRow,3);
r(2) = ySol(lastRow,4) - 1;
I am trying to implement a shooting method algorithm for solving a non-linear equation.
Thank you for your help,
Best regards.

7 commentaires

Torsten
Torsten le 5 Avr 2022
Why not using bvp4c ?
Wissem
Wissem le 5 Avr 2022
@Torsten Thank you for your reply : I didn't know about this function and I will surely look for it. However, I would also like to understand why this one is not working since I am trying to implement it. Thanks in advance.
Torsten
Torsten le 5 Avr 2022
Modifié(e) : Torsten le 5 Avr 2022
Did you save shoot4nl as "shoot4nl.m" in your working directory and now call it from a script named "shoot.m", e.g. ?
The other functions called (newtonRaphson2, runKut5) are also in this directory ?
Jan
Jan le 5 Avr 2022
Please post the complete errort message. In Which line does this error occur?
When I rund your code, I get a message about the missing "newtonRaphson2" function.
Wissem
Wissem le 5 Avr 2022
Yes, I did save the function as "shoot4nl.m" in the directory. Is there something wrong with calling this function from a new script ?
@Torsten@Jan This is the complete error obtained :
>> shoot4nl
Not enough input arguments.
Error in runKut5 (line 53)
if e <= eTol
Error in shoot4nl>residual (line 34)
[xSol,ySol] = runKut5(@dEqs,x,inCond(u),XSTOP,H);
Error in newtonRaphson2>jacobian (line 35)
f0 = feval(func,x);
Error in newtonRaphson2 (line 19)
[jac,f0] = jacobian(func,x);
Error in shoot4nl (line 14)
u = newtonRaphson2(@residual,u);
I wille edit my post to share the other functions in order to run properly what I wrote.
Thanks
Jan
Jan le 5 Avr 2022
Modifié(e) : Jan le 5 Avr 2022
Fine. This is useful. The problem occurs inside "runKut5". Most likely this function expects more inputs, than you provide in:
[xSol,ySol] = runKut5(@dEqs,x,inCond(u),XSTOP,H);
Please post the code of the failing function. What is "e" and "eTol"?

Connectez-vous pour commenter.

 Réponse acceptée

Voss
Voss le 5 Avr 2022

0 votes

There is a line in runKut5 that looks like it accidentally got commented out due to a comment on the previous line:
if nargin < 6; eTol = 1.0e-6; end
This line sets eTol to 1e-6 if it is not given as an input argument (it is the 6th input). Your calling function calls runKut5 with 5 inputs, so making this change should avoid the error. Updated runKut5.m is attached here.

2 commentaires

Wissem
Wissem le 5 Avr 2022
@_ Thank you for your help : it worked now. I didn't pay attention to this line : thanks !
Voss
Voss le 5 Avr 2022
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by