array indices and bisector method

1 visualización (últimos 30 días)
Michael
Michael el 21 de En. de 2021
Comentada: James Tursa el 22 de En. de 2021
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

Respuestas (1)

James Tursa
James Tursa el 21 de En. de 2021
Editada: James Tursa el 21 de En. de 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 comentario
James Tursa
James Tursa el 22 de En. de 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);

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by