array indices and bisector method

1 view (last 30 days)
Michael
Michael on 21 Jan 2021
Commented: James Tursa on 22 Jan 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

Answers (1)

James Tursa
James Tursa on 21 Jan 2021
Edited: James Tursa on 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 Comment
James Tursa
James Tursa on 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);

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!