From: Erwin Kuipers on
When performing symbolic computions with the symbolic toolbox, suddenly a symbol 'I' (capital i) appears in the expressions. This symbol causes the plotting command ezplot to produce an error:

??? Error using ==> char
Cell elements must be character arrays.

As a test I removed all 'I' symbols in the expression. ezplot was then capable of plotting the modified expression. So indeed the presence of the 'I' symbols seems to cause the error. However, I am wondering why this symbol is introduced at all and why I cannot find anything about this behavior in the MATLAB help.

I have been looking around in forums for similar issues but did not find anything. who can help me out on this? Thanks, Erwin
From: us on
"Erwin Kuipers" <erwin.kuipers.nl(a)gmail.com> wrote in message <i29cb4$kg2$1(a)fred.mathworks.com>...
> When performing symbolic computions with the symbolic toolbox, suddenly a symbol 'I' (capital i) appears in the expressions. This symbol causes the plotting command ezplot to produce an error:
>
> ??? Error using ==> char
> Cell elements must be character arrays.
>
> As a test I removed all 'I' symbols in the expression. ezplot was then capable of plotting the modified expression. So indeed the presence of the 'I' symbols seems to cause the error. However, I am wondering why this symbol is introduced at all and why I cannot find anything about this behavior in the MATLAB help.
>
> I have been looking around in forums for similar issues but did not find anything. who can help me out on this? Thanks, Erwin

this is a known issue and has been discussed in this NG...
unfortunately, i cannot find the thread (1-2 years ago) anymore...
can you show the code, which produces this output(?)...

us
From: Walter Roberson on
Erwin Kuipers wrote:
> When performing symbolic computions with the symbolic toolbox, suddenly
> a symbol 'I' (capital i) appears in the expressions

That is the symbolic toolbox representation of the imaginary number,
sqrt(-1)

Your result might be inherently complex, or your result might have
several values some of which are complex, or the symbolic engine might
have generated an imaginary quantity in an intermediate step and then
not yet have found a way to move it out to produce a pure real quantity.
From: us on
Walter Roberson <roberson(a)hushmail.com> wrote in message <g7Y1o.26619$cO.25149(a)newsfe09.iad>...
> Erwin Kuipers wrote:
> > When performing symbolic computions with the symbolic toolbox, suddenly
> > a symbol 'I' (capital i) appears in the expressions
>
> That is the symbolic toolbox representation of the imaginary number,
> sqrt(-1)
>
> Your result might be inherently complex, or your result might have
> several values some of which are complex, or the symbolic engine might
> have generated an imaginary quantity in an intermediate step and then
> not yet have found a way to move it out to produce a pure real quantity.

not quite...
the OP is referring to another phenomenon...
(i just cannot find the old thread...)

us
From: Erwin Kuipers on
"us " <us(a)neurol.unizh.ch> wrote in message <i29jpd$dnb$1(a)fred.mathworks.com>...
> Walter Roberson <roberson(a)hushmail.com> wrote in message <g7Y1o.26619$cO.25149(a)newsfe09.iad>...
> > Erwin Kuipers wrote:
> > > When performing symbolic computions with the symbolic toolbox, suddenly
> > > a symbol 'I' (capital i) appears in the expressions
> >
> > That is the symbolic toolbox representation of the imaginary number,
> > sqrt(-1)
> >
> > Your result might be inherently complex, or your result might have
> > several values some of which are complex, or the symbolic engine might
> > have generated an imaginary quantity in an intermediate step and then
> > not yet have found a way to move it out to produce a pure real quantity.
>
> not quite...
> the OP is referring to another phenomenon...
> (i just cannot find the old thread...)
>
> us

US and Walter, thanks for your replies. If 'I' is a representation of the imaginary unit sqrt(-1) why does the toolbox not use the commonly used symbol 'i'? Indeed, my calculations involve complex numbers. I have included the code here.

% Start of code --------------------------------
clear all
close all
clc

rho0 = sym('rho0','positive');
c0 = sym('c0','positive');
d = sym('d','real');
h = sym('h','real');
y = sym('y','real');
k = sym('k','positive');
x = sym('x','real');
r1 = sym('r1','positive'); % Distance source - calculation point
r2 = sym('r2','positive'); % Distance image source - calculation point

syms A % complex
%
% r1 = sqrt((x-d)^2+(y-h)^2)
% r2 = sqrt((x-d)^2+(y+h)^2)

p1 = A/r1*exp(-i*k*r1) % Complex sound pressure due to source
p2 = A/r2*exp(-i*k*r2) % Complex sound pressure due to image source

p = p1 + p2 % Total sound pressure

Z1 = rho0*c0*(i*k*r1/(1+i*k*r1)) % Spherical wave impedance
Z2 = rho0*c0*(i*k*r2/(1+i*k*r2)) % Spherical wave impedance

u1 = p1/Z1 % Particle velocity associated with source
u2 = p2/Z2 % Particle velocity associated with image source

cosalfa = (x-d)/r1 % Cosine of the angle of r1 with the x-axis
cosbeta = (x-d)/r2 % Cosine of the angle of r2 with the x-axis
sinalfa = (y-h)/r1 % Sine of the angle of r1 with the y-axis
sinbeta = (y+h)/r2 % Sine of the angle of r2 with the y-axis

ux = u1*cosalfa+u2*cosbeta % Total horizontal particle velocity
uy = u1*sinalfa+u2*sinbeta % Total vertical particle velocity
u = sqrt(ux^2 + uy^2) % Total particle velocity

Iacx = 1/2*real(p*conj(ux)) % Active intensity in x-direction
Iacy = 1/2*real(p*conj(uy)) % Active intensity in y-direction

w0pot = 1/(4*rho0*c0^2)*p*conj(p) % Potential energy density
w0kinx = 1/4*rho0*(ux)*conj(ux) % Kinetic energy density related to ux
w0kiny = 1/4*rho0*(uy)*conj(uy) % Kinetic energy density related to uy

w0x = w0pot + w0kinx % Total energy density related to ux
w0y = w0pot + w0kiny % Total energy density related to uy

Itotx = c0*w0x % Energy density multiplied with c0 to obtain a kind of intensity
Itoty = c0*w0y

Iinx = 1/2*(Itotx + Iacx) % Incident intensity
Ireflx = 1/2*(Itotx - Iacx) % Reflected intensity

alfax = Iacx/Iinx % Absorption coefficient

% Substitute the expressions for r1 and r2 in cartesian coordinates (x,y)
% of the calculation point and the coordinates of the source point (d,h)
alfax2 = subs(alfax,r1,sqrt((x-d)^2+(y-h)^2))
alfax3 = subs(alfax2,r2,sqrt((x-d)^2+(y+h)^2))

% Now substitute the known variables
alfaxf = subs(alfax3,[d x h rho0 c0 k A],[0 1 0.28 1.25 343 2*pi*800/343 2])

alfaxfreal = real(alfaxf)

ezplot(alfaxfreal,[0 2])

% End of code ------------------------------

The symbol 'I' starts to appear in the expression for alfax2, this is where I substitute the (real) expression r1 = sqrt((x-d)^2+(y-h)^2)) for the variable r1. As I defined x,d,y and h to be real, r1 will always be real. In fact, I only need the positive root.

Taking the real value of alfaxf does not remove the 'I' present in the expressions, so it seems that the toolbox has indeed trouble in evaluating the (rather large) expressions.

I have changed the code (putting the expressions for r1 and r1 directly at the top of the code) but that did not help. The 'I' then appeared in the expression for Iinx, so this is not much of use.

For a simpler case, that of an acoustic monopole source without reflective boundary, everything runs fine.

The key question is if there is some way to circumvent this issue.

Erwin