필터 지우기
필터 지우기

Inputting a time varying equation into system in simulink

조회 수: 88 (최근 30일)
Reed Smith
Reed Smith 2022년 12월 4일
댓글: Sam Chak 2022년 12월 7일
I am unsure of how to input a time varying equation into my system in simulink.
For example I want to input the function tau(t) = 0t for all t.
This gives me the option to change to a different time varying function instead of setting it to constant 0. However, I am unsure of how to do this because if i set my tau variable in workspace to 0, and try to input from workspace into my system it gives me an error message saying it must be a 2D matrix to account for the time values.
However, I do not know how to make my tau function into a matrix. I thought of using timeout variable however my simulink system does not run so I cannot use that variable.
Any help is appreciated as I am an absolute beginner when it comes to Simulink.
  댓글 수: 2
Sam Chak
Sam Chak 2022년 12월 4일
Do you want to insert the function tau(t), or to solve an implicit function tau(t) = 0 for t?
Reed Smith
Reed Smith 2022년 12월 4일
I would like to use the function tau(t) as an input for my system.

댓글을 달려면 로그인하십시오.

채택된 답변

Sam Chak
Sam Chak 2022년 12월 5일
편집: Sam Chak 2022년 12월 7일
Edit #2: As suggested in my original Answer, you can use the Clock to generated the time t vector, so that you can describe the time-based function tau as you wish. Here are 3 approaches:
Edit #1: There are a few options to compute the desired torque to stabilize the pendulum bob at the inverted position:
where the moment of inertia is .
You can construct one of these equations in Simulink using the basic blocks the same way as you showed in your image. The following example is coded in MATLAB instead of Simulink. Expect to get tghe same results in Simulink.
g = 10; % gravity
m = 0.4; % pendulum mass
l = 0.1; % pendulum length
params = [g m l]; % stored parameters
tspan = 0:0.01:3;
x0 = [-pi 0];
[t, x] = ode45(@(t, x) odefcn(t, x, params), tspan, x0);
plot(t, x(:,1), 'linewidth', 1.5), grid on
xlabel({'$t$'}, 'interpreter', 'latex')
ylabel({'$\theta(t)$'}, 'interpreter', 'latex')
title('Response of Inverted Pendulum')
% Inverted Pendulum
function xdot = odefcn(t, x, params)
xdot = zeros(2, 1);
g = params(1); % gravity
m = params(2); % pendulum mass
l = params(3); % pendulum length
Ix = m*(l/2)^2; % pendulum inertia
% Full 360° Computed Torque
tau1 = Ix*(- (g/l)*sin(x(1)) - (g/l)*x(1) - 2*sqrt(g/l)*x(2)); % Option #1
tau2 = Ix*(- 2*(g/l)*sin(x(1)/2) - (g/l)*tanh(x(1)) - 2*sqrt(g/l)*x(2)); % Option #2
% Non-360° Computed Torque
tau3 = Ix*(- 2*(g/l)*sin(x(1)) - 2*sqrt(g/l)*x(2)); % Option #3
% Dynamics
xdot(1) = x(2);
xdot(2) = (g/l)*sin(x(1)) + (1/Ix)*tau2; % select one of tau options
end
  댓글 수: 4
Reed Smith
Reed Smith 2022년 12월 7일
This is an awesome answer, seriously, thank you.
Sam Chak
Sam Chak 2022년 12월 7일
Don't mention it @Reed Smith. I'm glad for the opportunity to help you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sara Nadeau
Sara Nadeau 2022년 12월 5일
My question is whether the function tau is actually part of the system you are trying to model or whether it's just that the result of the function tau represents the input to the system you are trying to model. I am not sure how to interpret wanting to "use the function tau(t) as input for my system". I can help you use the result or output from tau(t) as input for your system, though.
If you're just using tau to generate the input signal you need for your system, I have some additional questions so I can try to help you figure out how to load the data:
  1. It looks like you are passing a time value to tau to generate the data you're trying to load. Do you have access to this time data to use in constructing the input signal? For most input loading formats, you do need to provide the time data.
  2. Are these values evenly spaced in time? Are you using a uniform sample rate or step size to generate the data? If not, you must provide time values to accurately depict the input data.
This page provides simple code examples to create data in each format the From Workspace block supports: Load Data Using the From Workspace Block. These formats are also supported by other loading blocks, including root-level Inport blocks.
  댓글 수: 4
Reed Smith
Reed Smith 2022년 12월 7일
Thank you, Sam, for your help. Sorry for the late responses!
It looks like this:
Here is a screenshot of my simulink setup. The only bit I am struggling with is inputting τ.
Hope this makes more sense. I feel as though I have completed the hard part and yet I'm clueless on inputting a time based signal.
Sam Chak
Sam Chak 2022년 12월 7일
You're welcome @Reed Smith. A few design options for tau, are suggested in my edited Answer above. Select one of the tau equations and construct it using basic blocks in Simulink, like you did above.
If you find the tau equations and MATLAB code helpful, please consider accepting ✔ and voting 👍 the Answer. Thanks a bunch! 🙏

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by