Step input applied for different seconds
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示

I want to apply step input to the system as in the graphs above, where the second values are seen in the row and column. Entries will start at 1 second and end at 5 and 40 seconds respectively. I want to plot the vibration graph x(t), and the amplitude graph of these vibrations, but I couldn't find where to start.
採用された回答
Star Strider
2022 年 12 月 21 日
Experiment with this approach —
N = 1500; % Desired Length Of Simulation
t = linspace(0, 50, N);
u = @(tlen,lz) [zeros(1,lz) 10*ones(1,size(t(t<=tlen),2)-lz) zeros(1,size(t(t>tlen),2))]; % 'tlen'=Length Of '10' Region, 'lz'=Length Of Leading Zero Vector
u5 = u(5,2);
u40 = u(40,2);
figure
subplot(2,1,1)
plot(t, u5, 'g', 'LineWidth',1.5)
grid
title('u(5,2)')
axis('padded')
ylim([0 15])
subplot(2,1,2)
plot(t, u40, 'b', 'LineWidth',1.5)
grid
title('u(40,2)')
axis('padded')
ylim([0 15])

Use ‘t’ and ‘u(tlen,lz)’ as inputs to lsim to get the system response. Change ‘u(tlen,lz)’ to get the result you want.
.
10 件のコメント
Mustafa Furkan
2022 年 12 月 21 日
Thank you for the answer actually I have these graphs but I want to plot the vibration graph x(t), and the amplitude graph of these vibrations.
Star Strider
2022 年 12 月 21 日
My pleasure!
Use them as inputs to the lsim function, as I mentioned previously. See the documentation I linked to for that.
Example —
N = 1500; % Desired Length Of Simulation
t = linspace(0, 50, N);
u = @(tlen,lz) [zeros(1,lz) 10*ones(1,size(t(t<=tlen),2)-lz) zeros(1,size(t(t>tlen),2))]; % 'tlen'=Length Of '10' Region, 'lz'=Length Of Leading Zero Vector
sys = tf(3,[1 2 3]) % From The 'lsim' Documentation
sys =
3
-------------
s^2 + 2 s + 3
Continuous-time transfer function.
figure
subplot(2,1,1)
lsim(sys, u(5,2), t)
grid on
subplot(2,1,2)
lsim(sys, u(40,2), t)
grid on

Use my code here, with your system.
.
Mustafa Furkan
2022 年 12 月 21 日
I got it thank you.
Star Strider
2022 年 12 月 21 日
As always, my pleasure!
Mustafa Furkan
2022 年 12 月 25 日
編集済み: Mustafa Furkan
2022 年 12 月 25 日
@Star Strider hi again,
If I want to use the step function instead of the lsim function, how can I do that? I plot the step charts in this way by making very minor changes in the formula you wrote.

Is it possible to get step response using only this graph? (Thanks to the step function, the oscillation after the step can also be observed.)
Star Strider
2022 年 12 月 25 日
The step function itself cannot do what you want. The best you can do is to cobble together (i.e. concatenate) outputs from different step calls and plot them together —
systf = @(id) tf(3,[1 2 3], 'InputDelay',id); % From The 'lsim' Documentation, Adding 'InputDelay' As A Variable Argument To The Anonymous Function Implementation
N = 1500; % Desired Length Of Simulation
t = linspace(0, 50, N);
t0 = t(t<=5);
t5 = t(t>5);
opts = stepDataOptions;
opts.InputOffset = 0;
opts.StepAmplitude = 10;
[y{1},tout{1},x{1}] = step(systf(0),t0,opts);
opts.InputOffset = y{1}(end);
opts.StepAmplitude = -y{1}(end);
[y{2},tout{2},x{2}] = step(systf(5),t5,opts);
figure
plot(tout{1}, y{1})
hold on
plot(tout{2}, y{2})
hold off
grid

figure
subplot(2,1,1)
plot(tout{1}, y{1})
grid
axis([0 50 -2 12])
subplot(2,1,2)
plot(tout{2}, y{2})
grid
axis([0 50 -2 12])

t0 = t(t<=40);
t40 = t(t>40);
opts = stepDataOptions;
opts.InputOffset = 0;
opts.StepAmplitude = 10;
[y{1},tout{1},x{1}] = step(systf(0),t0,opts);
opts.InputOffset = y{1}(end);
opts.StepAmplitude = -y{1}(end);
[y{2},tout{2},x{2}] = step(systf(40),t40,opts);
figure
plot(tout{1}, y{1})
hold on
plot(tout{2}, y{2})
hold off
grid

figure
subplot(2,1,1)
plot(tout{1}, y{1})
grid
axis([0 50 -2 12])
subplot(2,1,2)
plot(tout{2}, y{2})
grid
axis([0 50 -2 12])

Combining 'InputDelay' with the system object ‘systf’ (making that an anonymous function for convenience) and the step options structure stepDataOptions together makes this work. (I learned something about both functions in the process.)
It would be possible to use a for loop for this, and with more such simulations that would be an option, however with only two iterations, it didn’t seem worth the effort.
.
Mustafa Furkan
2022 年 12 月 25 日
Unable to perform assignment because brace indexing is not supported for
variables of this type.
Error in deneme22 (line 11)
[y{1},tout{1},x{1}] = step(systf(0),t0,opts);
Star Strider
2022 年 12 月 25 日
As always,. my pleasure!
It runs without error for me.
The most likely problem is that you defined one of those variables as something other than a cell array earlier in your code. Since I have no idea what that could be, rename those outputs to something else that does not confilct with already existing variables, for example:
[ys{1},touts{1},xs{1}] = step(systf(0),t0,opts);
or something else appropriate. Do that for all the step calls.
You will need to change the variable names, since I have no idea what the precise problem is, only what I believe could be causing it. Any valid MATLAB variable names will work.
.
Mustafa Furkan
2022 年 12 月 25 日
It worked now thank you. Unfortunately, as you said, I don't get a different result than before. I guess I'll have to include values like mass stiffness to get a result as expected.
Star Strider
2022 年 12 月 25 日
As always, my pleasure!
I have no idea what results are expected. It would appear that you would be using a state space realisation. There are likely documentation examples that could help code your system.
If necessary, you can use stepinfo with the arguments of all the step calls to get that information from each of them.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Plot Customization についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
