Display maximal value in a range?
2 次查看(过去 30 天)
显示 更早的评论
Hello. I would like to display the max(abs(sigma)) from around t=7 to t=10 from this code. The plot is from 0 to 10 and I tried to display that max value but it shows me the maximum value from the whole range (from 0 to 10) instead from 7 to 10. How can I do it? Here’s my code:
clear all
t=0;% initial time
x=[1,1,1];% initial condition for t=0
alpha=30;
tau=0.0001;
k=1; % counter
while t<=10
f=-sin(t+5)-0.5*cos(t)-x(2);
v=x(1);
vc=sin(t+1)-cos(0.5*t-2);
vcc=cos(t+1)+0.5*sin(0.5*t-2);
sigma=v-vc;
sigmadot=f-vcc;
u=alpha*((abs(sigmadot)).^2*sign(sigmadot)+sigma)/((sigmadot).^2+abs(sigma));
dx=[f,cos(1+x(1)+x(3))+(2-cos(x(1)+x(3)+1))*u,cos(x(1)+0.5*x(3)-t)-x(3)+u];
x=x+dx*tau;
t=t+tau;
sigmav(k)=sigma;
sigmadotv(k)=sigmadot;
tv(k)=t;
k=k+1;
end
figure
plot(tv,sigmav,'b',tv,sigmadotv,'r')
Help is appreciated!
0 个评论
采纳的回答
Star Strider
2019-8-10
编辑:Star Strider
2019-8-10
I do not see any max function calls, so I am not certain what result you want.
Displying only the values for ‘tv’ between 7 and 10 is straightforward:
Lidx = (tv>=7) & (tv<=10);
figure
plot(tv(Lidx),sigmav(Lidx),'b',tv(Lidx),sigmadotv(Lidx),'r')
with ‘Lidx’ being the logical index vector. This will select the values of the vectors you want.
To display ‘max(abs(sigma))’, assuming you intend ‘sigmav’:
maxSigma = max(abs(sigmav(Lidx)))
maxSigma =
4.451070235722554e-07
If you simply want to restrict the plot, you can also do that with the xlim function.
3 个评论
更多回答(1 个)
KALYAN ACHARJYA
2019-8-10
编辑:KALYAN ACHARJYA
2019-8-10
"I would like to display the max(abs(sigma)) from around t=7 to t=10 from this code"
Is this one:
t=0;% initial time
x=[1,1,1];% initial condition for t=0
alpha=30;
tau=0.0001;
k=1; % counter
l=1;
while t<=10
f=-sin(t+5)-0.5*cos(t)-x(2);
v=x(1);
vc=sin(t+1)-cos(0.5*t-2);
vcc=cos(t+1)+0.5*sin(0.5*t-2);
sigma=v-vc;
%% I haved changed Here
if t>=7 & t<=10
sigma_update(l)=sigma;
l=l+1;
end
%%
sigmadot=f-vcc;
u=alpha*((abs(sigmadot)).^2*sign(sigmadot)+sigma)/((sigmadot).^2+abs(sigma));
dx=[f,cos(1+x(1)+x(3))+(2-cos(x(1)+x(3)+1))*u,cos(x(1)+0.5*x(3)-t)-x(3)+u];
x=x+dx*tau;
t=t+tau;
sigmav(k)=sigma;
sigmadotv(k)=sigmadot;
tv(k)=t;
k=k+1;
end
figure
plot(tv,sigmav,'b',tv,sigmadotv,'r');
disp(max(abs(sigma_update)));
Result:
4.451070235722554e-07
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!