Error: Double cannot convert the input expression into a double array.
1 view (last 30 days)
Show older comments
The following is the program made by me which at the end gives me integral square error "integMinError". I wish to minimise this term using genetic algorithms.
function integMinError = GenAlgoRealTry(c)
orderNum = numel(n)-1
orderDen = numel(d)-1 %Order of original system
SystemOrig = tf(n,d)
PoleOrig = pole(SystemOrig)
for i = 1 : orderDen-order
NonDominantPole = min(PoleOrig)
PoleOrig(PoleOrig == NonDominantPole) = [] %This for loop helps to find non dominant poles and remove them from the transfer function
PoleOrig
end
[Numerato,ReducedDEN] = zp2tf([],PoleOrig,1) %Till now we have removed the dominant poles of the transfer function
%Now let us find the step response of the original system
unitStepFunc = tf([1],[1 0]); %Unit step function
yOrig= SystemOrig*unitStepFunc
syms s
[Num,Den] = tfdata(yOrig);
y_syms = poly2sym(cell2mat(Num),s)/poly2sym(cell2mat(Den),s)
yt = ilaplace(y_syms) %After a few transformations here we get the original unit step response
ReduNumMat = sym('A',[1 order]) %Reduced numerator whereas reduced denominator is PoleOrig
ReduNumMat2 = fliplr(ReduNumMat)
c = sym('A',[1 order])
for i = 1 : order+1
ReducedDENstep(i) = ReducedDEN(i)
end
ReducedDENstep(order+2)= 0
%Calculation of output of Reduced model
syms x
q = poly2sym(ReducedDENstep)
p = poly2sym(ReduNumMat2,x)
r = p/q
yred = ilaplace(r)
%Now we will match the steady state response of the system
syms t A1
eqn = limit(yred,t,inf)==limit(yt,t,inf);
solA = solve(eqn,A1)
A1 = solA
%Calculate error between step response of original and reduced model
err = yt - yred
errfinal = subs(err, sym('A1'), A1)
%Calculation of ISE to be minimised using Genetic Algorithm
integMinError = int(errfinal^2,'t', 0, inf)
So to minimise this term I make a separate file abc.m
n = input('Enter the numerator coefficients in square brackets in decreasing powers')
d = input('Enter the denominator coefficients in square brackets in decreasing powers')
order =input('Enter the order into which you wish to reduce the system')
FitnessFunction = @(c)GenAlgoRealTry(c,n,d,order);
numberOfVariables = order-1;
[c,fval] = ga(FitnessFunction,numberOfVariables)
When I run the above file I get an error :The following error occurred converting from sym to double: Error using mupadmex Error in MuPAD command: DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use the VPA function instead. What mistake I am doing? What should I do to minimise the integMinError using Genetic Algorithm?
I understand the error is because ga takes only double expression and mine integMinError has sym A2 A3. but dont know how to correct it.
0 Comments
Answers (1)
John D'Errico
on 23 Feb 2017
Edited: John D'Errico
on 23 Feb 2017
You are (apparently) the author of the code.
You never defined the variable order, yet you use it, here for example first, but in several other spots too.
for i = 1 : orderDen-order
what should you do? I'd suggest a good start is to define your variables before you try to use them. Or maybe you wanted to write something else there, so the answer is to use variables that you have already defined. :)
5 Comments
Walter Roberson
on 25 Feb 2017
Your abc calls a completely different routine than the one who's source you posted. Look at the function name. Real compared to Alternative
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!