I keep getting the "not enough inputs error" and I don't know how to fix it
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Stephen23
2024-11-30
编辑:Stephen23
2024-11-30
"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));
format short G
disp(out)
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
0 个评论
Torsten
2024-11-30
编辑:Torsten
2024-11-30
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)
double(xsol.x1)
double(xsol.x2)
double(xsol.x3)
double(xsol.x4)
double(xsol.x5)
double(xsol.x6)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!