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.

 Accepted Answer

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 Comments

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.
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.
.
I got it thank you.
As always, my pleasure!
@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.)
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.
.
Thank you for your effort @Star Strider. I get the following error:
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);
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.
.
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.
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.

Sign in to comment.

More Answers (0)

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!