Post by us Post by mohammad movassatPost by us Post by mohammad movassatE=char(g);
??? Error using ==> char
Cell elements must be character arrays.
Error in ==> looptest at 19
E=char(g);
any suggestion?
thank you,
- one of your CELL members is NOT a character...
c={'a',1,'b'};
char(c)
%{
??? Error using ==> char
Cell elements must be character arrays.
%}
us
a = sym('a');
x = sym(zeros(1, 2));
for k = 1:2,
x(k) = sym(sprintf('x%d', k));
end
f=a^3*x(1)+a^2*x(2)+2*a;
h=diff(f,a);
g = cell(1, 2);
teta=1;
for k = 1:2
g{k} = subs(h, a, teta);
teta=teta+1;
end
E=char(g);
the reason I have to convert them to char is that I need to write them in m-file as function and then call fsolve to solve them (solve two equations with two unknowns x(1) and x(2)). So what do you think? please let me know.
interesting problem since the obvious approach does not work in this case
r=char([g{:}])
% r = matrix([[3*x1 + 2*x2 + 2,12*x1 + 4*x2 + 2]])
% the sym-engine concatenates the sym-objs BEFORE the CHAR conversion
% takes place
% thus, another (more tedious) solution
%{
% r =
3*x1 + 2*x2 + 2
12*x1 + 4*x2 + 2
%}
us
Hi,
thanks for your response, I ran it with
r=char(cellfun(@(x) char(x),g,'uni',false).'),
here is the whole code:
clear;
clc;
a = sym('a');
x = sym(zeros(1, 2));
for k = 1:2,
x(k) = sym(sprintf('x%d', k));
end
f=a^3*x(1)+a^2*x(2)+2*a;
h=diff(f,a);
g = cell(1, 2);
teta=1;
for k = 1:2
g{k} = subs(h, a, teta);
teta=teta+1;
end
r=char(cellfun(@(x) char(x),g,'uni',false).')
and I got this error:
??? Too many inputs.
Error in ==> looptest at 19
r=char(cellfun(@(x) char(x),g,'uni',false).')
any suggestions?
thank you,
Mohammad