943,902 Members | Top Members by Rank

Ad:
Apr 20th, 2008
0

Matlab Help

Expand Post »
Hello everyone, I have a Matlab program that I got and want to run it on my PC. It gives me errors even though I'm 100% sure of the program and the data entry.My problem is in the function calling somewhere please help. My final is due this monday .
I have attached the code below, thank you for all the support.

%  Program name:  zerodynamics_tracking_comparison_Ex6_6_5_main
%  The purpose of this example is to compare the tracking performance of a
%  fully and partially linearizable system resulting from different choices
%  of the output equations.
clc, clear all, close all, format short g
global g K KK ro rro ncon
%%  Normal-form system matrices in controllable canonical form
Ac=[0 1; 0  0];						%  Controllable Ac in z-domain
Bc=[0;  1];						%  Controllable Bc in z-domain
Cc=[1  0];						%  Output matrix
D=0;							%   Throughput matrix
g=[0; 1];						%  g(x) matrix in xdot=f (x) +g (x) u
%%  Pole placement to design for normal form
zeta=0.7;  wn=6; wd=wn*sqrt (1-zeta^2)
p=[-zeta*wn+j*wd   -zeta*wn-j*wd]     					%  Chosen complex poles
K=place(Ac, Bc, p)					%  Poles placement gain matrix K
Acl=Ac-Bc*K;					%  CL system matrix in z-domain
%  Step response of y(t)=x1 (t) in the z-coordinates with r(t)=ro  (rad)
ro=8;
t=0: 0.01:2;
step (Acl,Bc*K(1)*ro,Cc,D,1,t) ;grid			%  Get y(t)=x1 (t) step response statistics
title ('Step response of fully linearizable system:  \rho=2=n:  y(t)=x_1(t)', 'fontsize',12)
xlabel ('t', 'fontsize',12), ylabel ('y(t)=x_1(t) ', 'fontsize',12)
%%  Case 1:  Step responses of fully linearizable system
ro=8;							%  Step input r(t)=ro
x0=[0; 0.2];						%  Initial condition of x
t=0:0.01:2;
ncon=1;						%  Case 1
[t,x]=ode23 ('zerodynamics_tracking_comparison_Ex_6_6_5_fn', t, x0);
figure,plot(t,x(:,1),t,x(:,2), '--', 'linewidth',1.5),grid
xlabel('t (sec) ', 'Fontsize',12)
title('Step response of fully linearizable system:\rho=2:x_1(t)==>ro=8,x_2(t)','fontsize',12)
legend('x_1(t)', 'x_2(t) ', 'location', 'best')
%%  Case 2:  Step responses of normal form – note that this system is not robust
rro=2;
KK=4.2;						%  Control gain = closed-loop pole
t=0:0.01:6;
x0=[0; 0.2];						%  Initial condition of x
ncon=2;						%  Case 2
[t,x]=ode23('zerodynamics_tracking_comparison_Ex_6_6_5_fn',t,x0);
figure,plot(t,x(:,1),t,x(:,2), '—','linewidth',1.5)grid
xlabel('t(sec)', 'Fontsize',12)
title('Step responses of normal form:  \rho=1: x_1(t), x_2(t) ==>r(t)=2',
'fontsize',12)
legend('x_1(t) '',x_2(t) ', 'location','best')
n=2*[4.2]; d = [1 4.2];	%  Get the settling time of Case 2
figure,step(n,d),grid


%  Function name:  zerodynamics_tracking_comparison_Ex6_6_5_fn
%  function xdot=zerodynamics_tracking_comparison_Ex_6_6_5_fn
%  The purpose of this example is to compare the tracking performance of a
%  fully and partially linearizable system resulting from different choices
%  of the output equations.

function xdot=zerodynamics_tracking_comparison_Ex_6_6_5_fn(t,x)

global g K KK ro rro  ncon   

f=[-x(1)+x(2)^3;-x(2)];
alpha=x(1)-4*x(2)^3; 
Dx=3*x(2)^2;					%  Decoupling matrix

%%  Case 1:  Step input for fully linearizable system
if ncon==1						%  Case 1

	z=[x(1);-x(1)+x(2)^3];			%  Transformation z=T(x)
	v=-K(1)*z(1)+K(2)*z(2)+K(1)*ro;	%  z-domain linear tracking control law
	u=inv(Dx)*(-alpha+v);	%  Linearizing feedback tracking control law
else							%  Case 2

%%  Case 2:  Step input for normal form
             alpha=-x(2);
             Dx=1;
             v=-KK*(x(2)-rro);
             u=inv(Dx)*(-alpha+v); %  Linearizing feedback tracking control law

end

      xdot=f+g*u;
Last edited by John A; Apr 20th, 2008 at 2:29 am. Reason: added code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tinazmail is offline Offline
1 posts
since Apr 2008
Apr 20th, 2008
0

Re: Matlab Help

what programming language is that ? Need to move this thread to the appropriate board for that language.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Apr 20th, 2008
1

Re: Matlab Help

I added code tags, but I see it didn't help much. Also, we don't have a category for the Matlab programming language, so instead I've moved it to "legacy and other languages".
Last edited by John A; Apr 20th, 2008 at 2:32 am.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
May 6th, 2008
0

Re: Matlab Help

What was the error actually. This is a .m script and better if you post the error message.
Reputation Points: 64
Solved Threads: 7
Junior Poster
shouvik.d is offline Offline
198 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Legacy and Other Languages Forum Timeline: J# invalid paramater at runtime
Next Thread in Legacy and Other Languages Forum Timeline: How do I set up and use a "whitelist" for forms?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC