bisector method help and inputs

3 visualizzazioni (ultimi 30 giorni)
henry Jok
henry Jok il 23 Gen 2021
Commentato: Steven Lord il 24 Gen 2021
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

Risposte (1)

Steven Lord
Steven Lord il 23 Gen 2021
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 Commenti
henry Jok
henry Jok il 23 Gen 2021
Hello, yes sorry here it is.
function [z]= APFunction (c,k,x)
[F,td] = myfunction(x);
w=sqrt(k/c);
k=k*1e6;
period = (2*pi) / w;
dt = period/1000;
tmax = 2*period;
t=0:dt:tmax;
% period 1 : t <= Td
t1 = t(t<=td);
z1= (F/k)*(1-cos(w*t))+(F/(k*td)*((sin(w*t)/w)-t));
% period 2 : t > Td
t2 = t(t>td);
z2=(F/(k*w*td))*(sin(w*t)-sin(w*(t-td)))-((F/k)*cos(w*t));
z = max([z1,z2]);
z= z*1000000;
end
Steven Lord
Steven Lord il 24 Gen 2021
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.

Accedi per commentare.

Categorie

Scopri di più su Language Fundamentals in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by