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!