필터 지우기
필터 지우기

How to simplify this function?

조회 수: 2 (최근 30일)
Shilp Dixit
Shilp Dixit 2013년 1월 18일
Hi,
I want to create u as a function of two variables x1 and x2 with the conditions as follows: if true
U = G(a.s1+(1-a).s2);
% Here
% G is a constant
% a is a constant
% s1 and s2 are functions of x1 and x2 and are described below
end
if true
% s1 as func. of x1,x2
if x1(x1-x2) >= 0
s1 = x1;
else
s1 = 0;
% s2 as func. of x1, x2
if -x2(x1-x2) >= 0
s2 = x2;
else
s2 =0;
end
end
To achieve this is I wrote a modified Signum function(modsign): http://tny.cz/e67c7d01
and use it to define the parameter U as
if true
U = G(a*x1*modsign(x1(x1-x2),0) + (1-a)*x2*modsign(-x2(x1-x2),0));
end
Please suggest a better and simpler way to do it. Preferably I want U, s1 and s2 as functions of x1 and x2 without using this convoluted way that I have used.
Thanks.
Shilp
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 1월 18일
Are you sure that you want to index x1 by the difference between x1 and x2?
x1(x1-x2)
is an indexing operation.
Perhaps you want multiplication in there?
x1 * (x1-x2)
??
Shilp Dixit
Shilp Dixit 2013년 1월 18일
Sorry about the confusion. I want multiplication everywhere.

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

답변 (2개)

Thorsten
Thorsten 2013년 1월 18일
편집: Thorsten 2013년 1월 18일
Note that x times y is coded x*y in Matlab.
I would go straigthforward
function U = myfunction(x1, x2)
G = 1.0; % replace with your constants
a = 0.5;
if x1*(x1 - x2) >= 0
s1 = x1;
else
s1 = 0;
end
if -x2*(x1 - x2) >= 0
s2 = x2;
else
s2 =0;
end
U = G*(a*s1 + (1-a)*s2);
  댓글 수: 1
Shilp Dixit
Shilp Dixit 2013년 1월 18일
Hi Thorsten,
Thanks for your answer. Now here lies my problem.
1. U control input for the system.
2. x1 and x2 are states of the system.[x1, x2, x3, x4]
I wanted to create U as a function of x so that could create a lyapunov function to solve my sliding mode control surface. Entire problem is as follows:
1. Problem statement http://sdrv.ms/WMjL9a
Perhaps these will explain what I am trying to do better.
Thanks.
Shilp

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


Thorsten
Thorsten 2013년 1월 18일
Hi Shilp, please try to ask a more detailed, more Matlab specific question, may be then I could provide some help.
  댓글 수: 1
Shilp Dixit
Shilp Dixit 2013년 1월 18일
Hi,
I would be glad with some help in sliding mode control and its solution via lyapunov function in matlab.
I have a sliding surface as
if true
% Sliding Surface
S = C.x
% C is 1X4 and x is 4X1.
% Ideally C.x = 0
% lyapunov function
V = 0.5*S^2 % 0.5 times S squared
% differentiating w.r.t x
V' = S.S'
% lyapunov function criteria
S.S' < 0 for all S ~=0
end
How do I find out the coeff of matrix C using this method in MATLAB.
Thanks. Shilp

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

카테고리

Help CenterFile Exchange에서 Matrix Computations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by