array indices and bisector method

1 次查看(过去 30 天)
Michael
Michael 2021-1-21
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

回答(1 个)

James Tursa
James Tursa 2021-1-21
编辑:James Tursa 2021-1-21
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 个评论
James Tursa
James Tursa 2021-1-22
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);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by