View Full Version : Help! Frustrating MATLAB Error!!
DrCube
03-03-2009, 07:16 PM
I ordinarily can resolve my MATLAB errors with lots of googling and a bit of trial and error, but this one has me particularly stumped.
I hope this doesn't run afoul of the homework rules here, but this is a small aspect of a larger project. And in any case, I'm supposed to be learning about control systems analysis, not MATLAB. I would liken it to asking about the details of a calculator whilst doing math homework. I'm not, repeat NOT, asking about control systems here. MATLAB is the tool, not the homework.
Disclaimer aside, here goes:
My goal is to plot the unit step response of a unity feedback amplifier, with open loop gain, G = k/((3*s+1)*(2*s+1)), for k=10. The code looks like this:
k=10;
G=k/((2*s+1)*(3*s+1));
T=G/(1+G);
C=ilaplace(T/s);
figure (4)
ezplot(C)
This works perfectly. However, when I move on to step 2, adding another pole at s=100, is when the shit hits the fan. Here's my code:
k=10;
G=k/((2*s+1)*(3*s+1)*(1+s/100));
T=G/(1+G);
D=ilaplace(T/s);
figure (5)
ezplot(D)
I get all sorts of errors, starting with inlineeval:
??? Error using ==> inlineeval
Error in inline expression ==> -1000./121524455857.*sum((27047643+61502320.*_alpha+612012.*_alpha.^2).*exp(_alpha.*t),_alpha = RootOf(605.*_Z.^2+501.*_Z+1100+6.*_Z.^3))
??? Error: The input character is not valid in MATLAB statements or expressions.
Error in ==> inline.feval at 34
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
Error in ==> specgraph\private\ezplotfeval at 54
z = feval(f,x(1));
Error in ==> ezplot>ezplot1 at 448
[y,f,loopflag] = ezplotfeval(f,x);
Error in ==> ezplot at 148
[hp,cax] = ezplot1(cax,f{1},vars,labels,args{:});
Error in ==> sym.ezplot at 46
h = ezplot(f.s);
Error in ==> Project2 at 70
ezplot(D)
I've since decided that this occurs whenever I add a third pole to the system, no matter what it is. Why would simply adding a third pole cause built-in MATLAB functions to stop working?
rbroome
03-03-2009, 10:30 PM
I hope to be pleasantly surprised but IMHO this post is pretty specific even for the Dope. If it was something simple like how to code a GUI in Matlab or do some time series analysis, no sweat. But for this question I think it is time to trot over to:
http://www.mathworks.com/support/
If you can't find the answer anywhere else, I just registered for a how to seminar hosted by Mathworks where we are encouraged to bring our hard problems for them to solve. The speakers are good. It is in a couple of weeks. :)
Frankly, it looks like a bug in Matlab (I know... the horror! but it HAS happened) :)
good luck.
My experience with MATLAB's symbolic toolbox is rather limited, but I believe it relies on Maple's computer algebra system. The output of your inverse Laplace transform command suggests that Maple couldn't provide a closed-form solution. Instead, Maple gave an implicitly-defined solution, which is unintelligible to MATLAB's 'ezplot' command. You might have to generate a vector of function evaluations and use the ordinary 'plot' command.
Polerius
03-04-2009, 01:14 AM
My goal is to plot the unit step response of a unity feedback amplifier, with open loop gain, G = k/((3*s+1)*(2*s+1)), for k=10. The code looks like this:
k=10;
G=k/((2*s+1)*(3*s+1));
T=G/(1+G);
C=ilaplace(T/s);
figure (4)
ezplot(C)
This works perfectly. However, when I move on to step 2, adding another pole at s=100, is when the shit hits the fan. Here's my code:
k=10;
G=k/((2*s+1)*(3*s+1)*(1+s/100));
T=G/(1+G);
D=ilaplace(T/s);
figure (5)
ezplot(D)
I get all sorts of errors, starting with inlineeval:
In the first case, C is a straightforward function of t
C = 10/11-10/11*exp(-5/12*t)*cos(1/12*239^(1/2)*t)-50/2629*239^(1/2)*exp(-5/12*t)*sin(1/12*239^(1/2)*t)
In the second case, D is not that straightforward
D = 10/1336769014427*sum((-54101682857+15690610815*_alpha+162285858*_alpha^2)*exp(_alpha*t),_alpha = RootOf(605*_Z^2+6*_Z^3+501*_Z+1100))+10/11
It has the "_alpha = RootOf(...)" expression in it.
This is what is confusing ezplot, which is expecting a simple function.
One potential solution is to convert
_alpha = RootOf(605*_Z^2+6*_Z^3+501*_Z+1100)
to the Matlab-friendly
alpha = roots([6 605 501 1100]);
and then
D2 = 10/1336769014427*sum((-54101682857+15690610815*alpha+162285858*alpha.^2).*exp(alpha*t)) +10/11
Try ezplot(D2)
Polerius
03-04-2009, 01:39 AM
Another way around it:
maple('k:=10;')
maple('G:=k/((2*s+1)*(3*s+1)*(1+s/100));')
maple('T:=G/(1+G);')
maple('C:=invlaplace(T/s,s,t)')
C = maple('evalf(C)');
figure(1)
clf
ezplot(C)
i.e. force maple to evaluate the complex symbolic expression
rbroome
03-04-2009, 07:40 AM
Another way around it:
maple('k:=10;')
maple('G:=k/((2*s+1)*(3*s+1)*(1+s/100));')
maple('T:=G/(1+G);')
maple('C:=invlaplace(T/s,s,t)')
C = maple('evalf(C)');
figure(1)
clf
ezplot(C)
i.e. force maple to evaluate the complex symbolic expression
I sit here pleasantly surprised.
:)
MikeS
03-04-2009, 10:10 AM
My experience with MATLAB's symbolic toolbox is rather limited, but I believe it relies on Maple's computer algebra system. The output of your inverse Laplace transform command suggests that Maple couldn't provide a closed-form solution. Instead, Maple gave an implicitly-defined solution, which is unintelligible to MATLAB's 'ezplot' command. You might have to generate a vector of function evaluations and use the ordinary 'plot' command.The real question here is why Maple doesn't automatically evaluate the roots of a cubic polynomial, but (apparently) does automatically evaluate the roots of a quadratic polynomial. There's a closed-form analytic expression for both of them, and in this case the roots are all real (in fact, they're the poles of the original function you're transforming.)
DrCube
03-04-2009, 02:42 PM
Wow, guys, thanks for the replies!
I figured it was worth a shot asking here, because I know there are posters who've said they use MATLAB everyday. But after watching this thread sink for several hours last night, I gave up and changed my entire approach.
I ended up using the Control Systems toolbox (:smack:) instead of Symbolic Math, using "step" to plot the step response to the transfer function in the form of step(num, den, t) where num and den were the numerator and denominator of my transfer function and t was the vector I plotted it over.
I'm completely inexperienced with Maple. I had no idea that the Symbolic Math toolbox used it so extensively. I'm going to do some research into Maple, because I know MATLAB can use it and it probably will come in handy in the future.
Even though I eventually solved my problem with a different approach, I'm going to bookmark this thread because I've had very similar problems before.
Thanks again for the help, I knew I could count on the Dope!
Una Persson
03-04-2009, 04:39 PM
Just chiming in to say that I'm really shocked MATLAB is still around. I was using it back when Bush Sr. was in office.
GargoyleWB
03-04-2009, 05:05 PM
Yep, I'm in grad school right now and Matlab is still what we're using.
I was late answering, my thought was that it was also a toolbox problem, and that you should check your version/toolbox for the supported function. Complex transforms are often wonky unless explicity tailored by a toolbox. The Student releases of Matlab often have crippled toolboxes that you only discover the week that your major project is due :)
I feel your pain, I've had many forehead-->keyboard bashing session in my Digital Signals classes.
rbroome
03-04-2009, 08:34 PM
Just chiming in to say that I'm really shocked MATLAB is still around. I was using it back when Bush Sr. was in office.
It is more popular (and more expensive) than ever. When time is money, it is great. But at $2K/seat, it ain't cheap.
robby
03-04-2009, 09:48 PM
Just chiming in to say that I'm really shocked MATLAB is still around. I was using it back when Bush Sr. was in office.Me too. I was a teaching assistant for a self-paced MATLAB course all through college, which was also when Bush Sr. was in office. :) Anyway, it was also the main programming language that I used for engineering classes in college.
It was a great improvement over APL (http://en.wikipedia.org/wiki/APL_(programming_language)), which was on its way out by the mid 1980s. (Good riddance.)
It is more popular (and more expensive) than ever. When time is money, it is great. But at $2K/seat, it ain't cheap.I had a student version that I used in grad school that was only about $100. It was a full version, too, albeit that it ran on Mac OS 9.
rbroome
03-05-2009, 06:49 AM
Me too. I was a teaching assistant for a self-paced MATLAB course all through college, which was also when Bush Sr. was in office. :) Anyway, it was also the main programming language that I used for engineering classes in college.
It was a great improvement over APL (http://en.wikipedia.org/wiki/APL_(programming_language)), which was on its way out by the mid 1980s. (Good riddance.)
I had a student version that I used in grad school that was only about $100. It was a full version, too, albeit that it ran on Mac OS 9.
My daughter has a student version as well. And I haven't noticed that the toolboxes are crippled. But if it isn't being used as part an education, one needs to purchase the commercial license. And on top of the purchase price, the maintenance fee is something like $400/yr. OTOH, even the help files are so good I reference them at work to document the algorithms we are using.
hobscrk777
03-05-2009, 06:53 AM
The toolboxes aren't crippled in the student version? In my experience, the student version lacks a lot of the functionality of the full version. I remember one time a friend was trying to find the roots of a complicated polynomial (too complicated to solve analytically) and decided to use MATLATB. His student version didn't recognize any of the symbolic math commands, but once he got to the computer lab (which has the pro version) he solved it just fine.
vBulletin® v3.7.3, Copyright ©2000-2013, Jelsoft Enterprises Ltd.