# Plotting a curve using two interdependent intervals

4 views (last 30 days)
Alexandru_Gherghescu on 30 Nov 2023
Answered: Chunru on 1 Dec 2023
Hello,
I am trying to plot the braking distance graph for a vehicle braking where the speed "v" ranges from 0 to 373 km/h and the real friction coefficient "ux" is a function of the standing grip coefficient "u" and decays by 10% with each 110 km/h of speed gained. The other values are constants, "t"=total reaction time, "a"=slope angle [rad], "p"=atmospheric pressure, "cx"=longitudinal drag coeff., "cz"=vertical drag coeff. (in this case downforce), "ax"=frontal area in square metres, 'm'=vehicle mass in kg.
This code also computes the mean deceleration as well as braking times with/without accounting for t.
This is the working code for computing the braking distance under a non-variable grip coefficient:
v=0:373; td=0.5; ts=0.2; g=9.81; a=0; p=1.204;
cx=0.35; cz=-0.05; ax=1.77; m=1240; u=1.2;
t=td+ts;
vmax=373/3.6;
w=m*g;
c0=(u*cos(a))+sin(a);
c2=p*ax*(cx-u*cz)/(w*2);
s=(log(1+((v/3.6).^2)*(c2/c0)))/(2*c2*g);
S=(log(1+((v/3.6).^2)*(c2/c0)))/(2*c2*g)+t*(v/3.6);
d=g*(c0+c2*(vmax.^2))
dG=d/g
BD=(log(1+((vmax).^2)*(c2/c0)))/(2*c2*g)
TBD=BD+t*vmax
ts=vmax/d
Ts=t+ts
hold on, grid on
plot (v,s, 'r'); plot (v,S, 'k')
However the script accounting for ux cannot be represented in the same way:
ux=u*(1-(3.6*(v/3.6)/1100));
c0x=(ux*cos(a))+sin(a);
c2x=p*ax*(cx-ux*cz)/(w*2);
sx=(log(1+((v/3.6).^2)*(c2x/c0x)))/(2*c2x*g);
Sx=(log(1+((v/3.6).^2)*(c2x/c0x)))/(2*c2x*g)+t*(v/3.6);
dx=g*(c0x+c2x*(vmax.^2))
dGx=dx/g
BDx=(log(1+((vmax).^2)*(c2x/c0x)))/(2*c2x*g)
TBDx=BDx+t*vmax
tsx=vmax/dx
Tsx=t+tsx
hold on, grid on
plot (v,sx, 'm'); plot (v,S, 'b')
MATLAB prompts the following script: "Error using / Matrix dimensions must agree."
I'd be grateful if anyone would be kind enough to help me out with plotting this function. Thank you in advance!

Chunru on 1 Dec 2023
You need array division ./ instead of /
v=0:373; td=0.5; ts=0.2; g=9.81; a=0; p=1.204;
cx=0.35; cz=-0.05; ax=1.77; m=1240; u=1.2;
t=td+ts;
vmax=373/3.6;
w=m*g;
c0=(u*cos(a))+sin(a);
c2=p*ax*(cx-u*cz)/(w*2);
s=(log(1+((v/3.6).^2)*(c2/c0)))/(2*c2*g);
S=(log(1+((v/3.6).^2)*(c2/c0)))/(2*c2*g)+t*(v/3.6);
d=g*(c0+c2*(vmax.^2))
d = 15.5542
dG=d/g
dG = 1.5855
BD=(log(1+((vmax).^2)*(c2/c0)))/(2*c2*g)
BD = 395.3939
TBD=BD+t*vmax
TBD = 467.9217
ts=vmax/d
ts = 6.6613
Ts=t+ts
Ts = 7.3613
hold on, grid on
plot (v,s, 'r'); plot (v,S, 'k')
ux=u*(1-(3.6*(v/3.6)/1100));
c0x=(ux*cos(a))+sin(a);
c2x=p*ax*(cx-ux*cz)/(w*2);
sx=(log(1+((v/3.6).^2)*(c2x/c0x)))/(2*c2x*g);
Sx=(log(1+((v/3.6).^2)*(c2x/c0x)))/(2*c2x*g)+t*(v/3.6);
dx=g*(c0x+c2x*(vmax.^2))
dx = 1×374
15.5542 15.5430 15.5318 15.5206 15.5094 15.4982 15.4870 15.4758 15.4646 15.4534 15.4422 15.4309 15.4197 15.4085 15.3973 15.3861 15.3749 15.3637 15.3525 15.3413 15.3301 15.3189 15.3077 15.2965 15.2853 15.2741 15.2629 15.2517 15.2405 15.2293
dGx=dx/g
dGx = 1×374
1.5855 1.5844 1.5833 1.5821 1.5810 1.5798 1.5787 1.5776 1.5764 1.5753 1.5741 1.5730 1.5718 1.5707 1.5696 1.5684 1.5673 1.5661 1.5650 1.5638 1.5627 1.5616 1.5604 1.5593 1.5581 1.5570 1.5558 1.5547 1.5536 1.5524
%whos
BDx=(log(1+((vmax).^2)*(c2x./c0x)))./(2*c2x*g) %<=============
BDx = 1×374
395.3939 395.7146 396.0358 396.3575 396.6798 397.0025 397.3258 397.6497 397.9740 398.2989 398.6243 398.9503 399.2768 399.6038 399.9314 400.2595 400.5882 400.9174 401.2471 401.5774 401.9082 402.2396 402.5715 402.9040 403.2370 403.5706 403.9048 404.2395 404.5747 404.9105
TBDx=BDx+t*vmax
TBDx = 1×374
467.9217 468.2424 468.5636 468.8853 469.2075 469.5303 469.8536 470.1774 470.5018 470.8267 471.1521 471.4781 471.8046 472.1316 472.4592 472.7873 473.1159 473.4451 473.7749 474.1052 474.4360 474.7674 475.0993 475.4318 475.7648 476.0984 476.4326 476.7673 477.1025 477.4383
tsx=vmax./dx %<=============
tsx = 1×374
6.6613 6.6661 6.6709 6.6757 6.6805 6.6854 6.6902 6.6951 6.6999 6.7048 6.7096 6.7145 6.7194 6.7243 6.7292 6.7341 6.7390 6.7439 6.7488 6.7537 6.7587 6.7636 6.7686 6.7735 6.7785 6.7835 6.7884 6.7934 6.7984 6.8034
Tsx=t+tsx
Tsx = 1×374
7.3613 7.3661 7.3709 7.3757 7.3805 7.3854 7.3902 7.3951 7.3999 7.4048 7.4096 7.4145 7.4194 7.4243 7.4292 7.4341 7.4390 7.4439 7.4488 7.4537 7.4587 7.4636 7.4686 7.4735 7.4785 7.4835 7.4884 7.4934 7.4984 7.5034
hold on, grid on
plot (v,sx, 'm'); plot (v,S, 'b')

### Categories

Find more on Repeated Measures and MANOVA in Help Center and File Exchange

R2017a

### Community Treasure Hunt

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

Start Hunting!