bisector method help and inputs
显示 更早的评论
Hello,
I'd like some help with my bissector method as it displays an error message each time I run it.
Error using APFunction
Too many input arguments.
Error in test2 (line 12)
[deflectionL,tL]= APFunction (PForceL,c,k,LoadingDurationL,tstep);
clc;clear;
c=800; k=5000000;
xL=0; xU= 10; Diff=1;
tstep=0.01;
while Diff > 0.01
xM = (xU-xL)/2;
[PForceL,LoadingDurationL] = myfunction(xL);
[PForceU,LoadingDurationU] = myfunction(xU);
[PForceM,LoadingDurationM] = myfunction(xM);
[deflectionL,tL]= APFunction (PForceL,c,k,LoadingDurationL,tstep);
[deflectionU,tU]= APFunction (PForceU,c,k,LoadingDurationU,tstep);
[deflectionM,tM]= APFunction (PForceM,c,k,LoadingDurationM,tstep);
MaxdL= max(deflectionL);
MaxdU= max(deflectionU);
MaxdM= max(deflectionM);
if MaxdM >0.1
xL=xM;
else
xU=xM;
end
Diff = abs(MaxdM-0.1);
end
回答(1 个)
Steven Lord
2021-1-23
0 个投票
You haven't showed the code for your APFunction, so all we can say is that you're calling it with five input arguments and it must be defined to accept fewer than five inputs.
2 个评论
henry Jok
2021-1-23
Steven Lord
2021-1-24
Here's how you're calling your function in your original code.
[deflectionL,tL]= APFunction (PForceL,c,k,LoadingDurationL,tstep);
Here's how the function is declared.
function [z]= APFunction (c,k,x)
The value stored in PForceL in the caller workspace will be assigned to the variable c in the workspace of this call to APFunction. Simillarly c in the caller workspace will be assigned to k in the workspace of this APFunction call and k in the caller will be assigned to x in the APFunction workspace.
LoadingDurationL arrives at the front desk to the APFunction hotel and asks for a room only for the desk clerk, MATLAB, to tell them "Sorry, no vacancies." There are only three rooms at the APFunction hotel.
Even if you fixed that, you'd have a problem at check-out time. The valet only has one car in the garage, but two guests want to pick up their vehicles when they leave the APFunction hotel.
I recommend writing up help text for your APFunction and/or using more descriptive variable names, to make it clearer how you expect users of your code to call it. How many inputs and outputs does APFunction expect / require and what do those inputs / outputs represent? Then update your test2 script to call it according to those expectations.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating Custom Adaptors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!