# MATLAB: Error message: DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use VPA.

fminsearchoptimizationsymbolic

Hello. I need your help. I am trying to use the optimazation function 'fminsearch' to find 8 unkown values. The function M file which I made is,
function y_1=opti_real(x)
global Ra Rb La Lb Ga Gb Ca Cb Zc Zc_A Gamma Z Y wm R L G C Frequency
wm=2*pi*Frequency;
syms Ra Rb La Lb Ga Gb Ca Cb real
wm=2*pi*Frequency;
R=[Ra, Rb, Rb; Rb, Ra, Rb; Rb, Rb, Ra;]; L=[La, Lb, Lb; Lb, La, Lb; Lb, Lb, La;]; G=[Ga, Gb, Gb; Gb, Ga, Gb; Gb, Gb, Ga;]; C=[Ca, Cb, Cb; Cb, Ca, Cb; Cb, Cb, Ca;];
Z=R+j*wm(1,1)*L; Y=G+j*wm(1,1)*C;
Gamma=sqrtm(Z*Y); Zc=Gamma*inv(Y);
Ra=x(1); Rb=x(2); La=x(3); Lb=x(4); Ga=x(5); Gb=x(6); Ca=x(7); Cb=x(8);
y_1=abs(real(Zc_A)-real(Zc));
where Ra, Rb, La, Lb, Ga, Gb, Ca, Cb are unkown parameters. Frquency and Zc_A are calculated values from main code. Zc_A is a 3 by 3 matrix that contains complex numbers. The main code to find the values of Ra, Rb, La, Lb, Ga, Gb, Ca, Cb is,
x=[R_open(1,1), 0, L_open(1,1), 0, G_open(1,1), 0, C_open(1,1), 0]; bb=fminsearch(@opti_real, x);
where, R_open(1,1)… are calculated real values in main code. After I run the main code, the error message is displayed as follows:
DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use VPA.
can you explain the problem and fix my code please?

• It would be much easier to read your code if you would use the {} Code button to format your code.
fminsearch expects a function that takes a single real initial vector and gives a single real scalar output. I think that you are making a mistake by using symbolic variables, but I cannot read your code to say exactly what is going on.
I suggest that you ensure that your function accepts a real input vector, say your x0, and returns a single real scalar output. I further suggest that you do not use any symbolic variables, as I am pretty sure that you can use MATLAB commands for all your calculations.
Alan Weiss
MATLAB mathematical toolbox documentation