Why is it shown "DOUBLE cannot convert the input expression into a double array."? And also all the variable turns to sym though I have only symbolized 3 variables.

lambda=sym('lambda','positive');
Z0=sym('Z0','positive');
Vi0=sym('Vi0','positive');
Ii0=(Vi0/Z0);
z=-lambda*(0:0.01:1.5);
gamma=1i*2*pi/lambda;
Zl=2*Z0; %case (a)
G1=reflCoeff(Zl,Z0);
V=abs(cplxVoltage(Vi0,gamma,G1,z));
I=abs(cplxCurrent(Ii0,gamma,G1,z));
V1=double(V/Vi0);
I1=double(I*Z0/Vi0);
x=(z/lambda);
figure(1);
plot(x,V1,'b',x,I1,'r--'); legend('|V|/Vi0','|I|*Z0/Vi0');
xlabel('z/\lambda');
ylim([0,2]);

回答(2 个)

I cannot run your code.
The most likely reason for the error is that at least one of these (the only double calls in the code you posted):
V1=double(V/Vi0);
I1=double(I*Z0/Vi0);
contains at least one symbolic variable in either ‘V/Vi0’ or ‘I*Z0/Vi0’.
You have
Z0=sym('Z0','positive');
Vi0=sym('Vi0','positive');
so any expression that uses either of those two variables is going to involve an unassigned symbolic value (unless the variable just happens to cancel out.)
You have
V=abs(cplxVoltage(Vi0,gamma,G1,z));
V1=double(V/Vi0);
The first of those two lines uses the unresolved symbolic variable Vi0. It also involves gamma, which was defined in terms of the unresolved symbolic variable lambda; and G1 is defined in terms of the unresolved symbolic variable Z0; and z is defined in terms of the unresolved symbolic variable lambda. Unfortunately you did not show us the code for cplxVoltage, but considering all the unresolved symbolic variables, we have good reason to expect that whatever cplxVoltage is, is not going to happen to ignore or have cancel lambda and Z0, and happen to involve Vi0 strictly linearly such that in the following line V/Vi0 will happen to have no remaining unresolved symbolic variables.
You probably need to leave out the double() conversion at that point, getting a result in some symbolic variables, and then use subs() to substitute in particular numeric values for the symbolic variables.
Meanwhile, you have
x=(z/lambda);
plot(x,V1,'b',x,I1,'r--'); legend('|V|/Vi0','|I|*Z0/Vi0');
which makes it appear as if V1 and I1 are dependent upon the value of x, but they are not. But it just might be the case that V1 and I1 would end up involving only the variable lambda, in which case,
plot(x, V1/lambda, 'b', x, I1/lambda, 'r--'); legend('|V|/Vi0','|I|*Z0/Vi0');
just might happen to work... depending on how cplxVoltage is defined.

Community Treasure Hunt

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

Start Hunting!

Translated by