array indices and bisector method
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I'm trying to find a root using the bisector method, using two functions I've made in previous files. Those functions are [PForce, LoadingDuration]= myfunction(x) and [z]= PFunction (m,k,x). I replaced the x by xL, xM and xU which are the values used to calculate the root. Each time I run it it says
Array indices must be positive integers or logical values.
Error in exercice2 (line 10)
z(xL) = PDFunction (m,k,xL);
I'm not really sure how to correct this so if anyone know i'd be happy to know !! Thanks a lot
Here is the full code:
clc;clear;
m=800; k=1e6;
xL=0; xU= 10; Difference=1;
tstep=0.0001;
while Difference > 0.0005
xM = (xU-xL)/2;
[PForceL,LoadingDurationL] = myfunction(xL);
[PForceU,LoadingDurationU] = myfunction(xU);
[PForceM,LoadingDurationM] = myfunction(xM);
z(xL) = PDFunction (m,k,xL);
z(xU) = PDFunction (m,k,xU);
z(xM) = PDFunction (m,k,xM);
MaxdL= max(deflectionL);
MaxdU= max(deflectionU);
MaxdM= max(deflectionM);
if MaxdM > 0.1
xL=xM;
else
xU=xM;
end
Difference = abs(MaxdM-0.1);
end
0 Kommentare
Antworten (1)
James Tursa
am 21 Jan. 2021
Bearbeitet: James Tursa
am 21 Jan. 2021
It is not clear what z is supposed to be used for in these lines:
z(xL) = PDFunction (m,k,xL);
z(xU) = PDFunction (m,k,xU);
z(xM) = PDFunction (m,k,xM);
You could simply delete these lines.
It is also not clear where the deflection variables are defined.
1 Kommentar
James Tursa
am 22 Jan. 2021
So could you just do this?
[deflectionL,tL]= PDFunction (PForceL,k,m,LoadingDurationL);
[deflectionU,tU]= PDFunction (PForceU,k,m,LoadingDurationU);
[deflectionM,tM]= PDFunction (PForceM,k,m,LoadingDurationM);
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!