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

1 次查看(过去 30 天)
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?

采纳的回答

Alan Weiss
Alan Weiss 2015-3-30
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
  3 个评论
Alan Weiss
Alan Weiss 2015-3-30
I believe that things will work much better for you if you follow my suggestion and remove all symbolic variables from your code.
Also, your code makes no sense to me, because the output y_1 does not depend on the input variable x, it only depends on some external global variables. So you need to rethink your entire code.
Alan Weiss
MATLAB mathematical toolbox documentation

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by