I keep getting the "not enough inputs error" and I don't know how to fix it

31 views (last 30 days)
global m1 m2 w1a w1w w1m w2m w2w w2a
m1 = 135;
m2 = 30.3455;
w1a = .220;
w1w = .780;
w1m = .000;
w2m = .202;
w2w = .798;
w2a = .000;
function F = Control_volume_4(x)
global m1 m2 w1a w1w w2m w2w
% x(1) = w1m
% x(2) = w2a
% x(3) = w3a
% x(4) = w3m
% x(5) = w3w
% x(6) = m3
F(1) = w1a + x(1) + w1w;
F(2) = x(2) + w2m + w2w;
F(3) = x(3) + x(4) + x(5) - 1;
F(4) = m1 * w1a + m2 * x(2) - x(6) * x(3);
F(5) = m1 * x(1) + m2 * w2m - x(6) * x(4);
F(6) = m1 * w1w + m2 * w2w - x(6) * x(5);
end
guess4 = zeros(1,6);
answer_CV4 = fsolve(Control_volume_4, guess4);
disp(answer_CV4)
i get the " not enough input arguments " error pointing at the x(1) in the F(1) equation

Answers (2)

Stephen23
Stephen23 on 30 Nov 2024 at 8:21
Edited: Stephen23 on 30 Nov 2024 at 8:32
"i get the " not enough input arguments " error pointing at the x(1) in the F(1) equation"
That error is caused by the fact that you called Control_volume_4 (without any input arguments) rather than providing a function handle to FSOLVE: What you did:
answer_CV4 = fsolve(Control_volume_4, guess4);
% ^^^^^^^^^^^^^^^^ here you *call* the function
What you should have done (as shown in the FSOLVE documentation):
answer_CV4 = fsolve(@Control_volume_4, guess4);
% ^ define a function handle, does not *call* the function
After fixing that you will likely need to fix some other errors. You should also avoid GLOBAL:
m1 = 135;
m2 = 30.3455;
w1a = 0.220;
w1w = 0.780;
w1m = 0.000;
w2m = 0.202;
w2w = 0.798;
w2a = 0.000;
fnh = @(x) Control_volume_4(x,m1,m2,w1a,w1m,w1w,w2a,w2m,w2w);
out = fsolve(fnh, zeros(1,6));
Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 6.000000e+02.
format short G
disp(out)
-0.99135 -0.97324 -128.38 -19842 19971 0.0064546
function F = Control_volume_4(x,m1,m2,w1a,w1m,w1w,w2a,w2m,w2w)
F = nan(1,6);
F(1) = w1a + x(1) + w1w;
F(2) = x(2) + w2m + w2w;
F(3) = x(3) + x(4) + x(5) - 1;
F(4) = m1 * w1a + m2 * x(2) - x(6) * x(3);
F(5) = m1 * x(1) + m2 * w2m - x(6) * x(4);
F(6) = m1 * w1w + m2 * w2w - x(6) * x(5);
end

Torsten
Torsten on 30 Nov 2024 at 10:18
Edited: Torsten on 30 Nov 2024 at 10:19
m1 = 135;
m2 = 30.3455;
w1a = .220;
w1w = .780;
w1m = .000;
w2m = .202;
w2w = .798;
w2a = .000;
syms x [6 1];
F(1) = w1a + x(1) + w1w;
F(2) = x(2) + w2m + w2w;
F(3) = x(3) + x(4) + x(5) - 1;
F(4) = m1 * w1a + m2 * x(2) - x(6) * x(3);
F(5) = m1 * x(1) + m2 * w2m - x(6) * x(4);
F(6) = m1 * w1w + m2 * w2w - x(6) * x(5);
xsol = solve(F==0)
xsol = struct with fields:
x1: -1 x2: -1 x3: -22711512183341056/569 x4: -4534217384621546375/569 x5: 4556928896804888000/569 x6: 569/35184372088832000
double(xsol.x1)
ans = -1
double(xsol.x2)
ans = -1
double(xsol.x3)
ans = -3.9915e+13
double(xsol.x4)
ans = -7.9687e+15
double(xsol.x5)
ans = 8.0087e+15
double(xsol.x6)
ans = 1.6172e-14

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!