Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

??? Error using ==> mldivide Matrix dimensions must agree.

Asked by Mohamed Yassin OUKILA on 21 Jun 2011

[EDIT: 20110621 11:43 CDT - reformat - WDR]

I have this error

??? Error using ==> mldivide
Matrix dimensions must agree.

however i can't find why it says 'cuz it's not a matrix it's a function...this is the code:

%--------------

k=1.7;
lambda=0.3;
tp=1;
nu = k*(1-exp(-lambda*tp));
t = 5:35;
Ec = nu*Eg(t-tp);
%graphe
plot(t,Ec)

------------------------------------

function y = Eg(t)
y = ilaplace(Egs(t),t,t);

------------------------------------

function y = Egs(s)
%constantes
a=14;
b=15;
c=25;
L=c-b;
r=c;
phi=15;
V=7*7*28;
ro=1000;
RHi=100;
RHb=50;
dRH = RHb-RHi;
nus=0.3;
D=1;
M=8.3*10^(-6);
k=1.7;
Es=200000;
nuc=0.2;
lambda=0.3;
tp=1;
nu = k*(1-exp(-lambda*tp));

%------------------------

D1 = s*Epssa(s)-(s+lambda)*Epssa(s+lambda)/exp(lambda*tp);
y = (1/k)*(a-b)*(a+b)*(Es/s)*D1*s*(b^2*(nuc-1)-c^2*(nuc+1))/(4*b^2*(s*Epsf(s)-(s+lambda)*Epsf(s+lambda))+(b-c)*(b+c)*D1*((a^2*(nus+1)-b^2*(nus-1))));

--------------------------------------------

function y = Epsf(s)
%constantes
a = 14;
b=15;
c=25;
L=c-b;
r=c;
phi=15;
V=7*7*28;
ro=1000;
RHi=100;
RHb=50;
dRH = RHb-RHi;
nus=0.3;
D=1;
M=8.3*10^(-6);
k=1.7;
Es=200000;
nuc=0.2;
lambda=0.3;
tp=1;
nu = k*(1-exp(-lambda*tp));
%-------------
%RH(c,s)
    %Bi
          B1 = b*sqrt(s)/sqrt(D);
          B2 = c*sqrt(s)/sqrt(D);
          B3 = r*sqrt(s)/sqrt(D);
          B4 = -b*exp(B2)*(b-r)*(b+r)*RHi*sqrt(s)-3*c*exp(B2)*(b-r)*(b+r)*sqrt(s);
          B5 = D^(7/4)*sqrt(pi)*dRH*(3*sqrt(D)-2*b*sqrt(s))*sqrt(-s/D)*(erf1(sqrt(b)*(s/D)^(1/4))-erf1(sqrt(r)*(s/D)^(1/4)))/(b^(3/2)*s^(9/4));
  RH= sqrt(D)*exp(-c*sqrt(s)/sqrt(D))*(-b*c*s/D)^(3/2)*((D)^(3/2)*sqrt(-b*c*s/D)*(-6*c^(3/2)*(sqrt(6*D)*exp(B1)-exp(B3)*sqrt(D*r))*dRH-B4)/(b^2*c^2*s^2)+B5)/(2*(3*c+b)*s^(3/2));
  y = -1.1*M*((c^2-b^2)*RHi/(2*s)-RH);

-----------------------------------------------

function ans = Epssa(s)
syms t;
Epsa = -16.7*10^(-6)*t^(0.3);
ans = laplace(Epsa,t,s);

-------------------------------------------

function ans=erfi1(t)
% %erfi(x). The Imaginary error function, as it is defined in Mathematica
% %erfi(z)==erf(iz)/i (z could be complex) using 
% %the incomplete gamma function in matlab: gammainc
% %Using "@": erfi = @(x) real(-sqrt(-1).*sign(x).*gammainc(-x.^2,1/2))
% %Note: limit(x->0) erfi(x)/x -> 2/sqrt(pi)
%
% %Example 1: 
% x=linspace(0.001,6,100);
% y=exp(-x.^2).*erfi(x)./2./x;
% figure(1), clf;plot(x,y*sqrt(pi))
%
% %Example 2: 
% [x,y]=meshgrid(linspace(-3,3,180),linspace(-3,3,180));
% z=x+i*y;
% figure(1), clf;contourf(x,y,log(erfi(z)))
% axis equal;axis off
xc=5.7;%cut for asymptotic approximation (when x is real)
ans=~isreal(t).*(-(sqrt(-t.^2)./(t+isreal(t))).*gammainc(-t.^2,1/2))+...
    isreal(t).*real(-sqrt(-1).*sign(t).*((t<xc).*gammainc(-t.^2,1/2))+...
    (t>=xc).*exp(t.^2)./t/sqrt(pi));

-----------------------------------------------

function y = erfi(s)
%syms t;
%f = 2/sqrt(pi)*t+2/(3*sqrt(pi))*t^3+1/(5*sqrt(pi))*t^5+1/(21*sqrt(pi))*t^7+1/(108*sqrt(pi))*t^9+1/(660*sqrt(pi))*t^11+1/(4680*sqrt(pi))*t^13+1/(37800*sqrt(pi))*t^15;
y = laplace(erfi1(s),s,s);

-----------------------------------

please help :)

0 Comments

Mohamed Yassin OUKILA

Products

No products are associated with this question.

4 Answers

Answer by Sean de Wolski on 21 Jun 2011

What line does it say the error is on? I'll bet it's on that line where you do a left matrix division '/'.

0 Comments

Sean de Wolski
Answer by Matt Tearle on 21 Jun 2011

Unless you actually want to do a matrix division, a simple solution is to do a find-n-replace: "/" -> "./"

Otherwise, please format your code and, as Sean says, show which line the error occurs on. For extra credit, you could put a breakpoint on that line, run the code again and do whos at the prompt when it stops on the error line.

0 Comments

Matt Tearle
Answer by Mohamed Yassin OUKILA on 21 Jun 2011

I actually changed this function y = Eg(t) y = ilaplace(Egs(t),t,t);

with this function y = Eg(t) syms s; y = ilaplace(Egs(s),s,t); and it works...however I have other problems...I'll put them in a different subject... sorry about the code...I'm new in here and thanks for your answers ;)

0 Comments

Mohamed Yassin OUKILA
Answer by Mohamed Yassin OUKILA on 21 Jun 2011

I found a function here in mathworks called Erfi that i have to use it in a program. however, as I understood, this function doesn't work for s as symbolic . however, i need to do ilaplace for a function that uses it... here is the error ----------------------------- ??? Undefined function or method 'gammainc' for input arguments of type 'sym'.

Error in ==> erfi1 at 19
ans=~isreal(t).*(-(sqrt(-t.^2)./(t+isreal(t))).*gammainc(-t.^2,1/2))+...
Error in ==> Epsf at 31
      B5 =
      D.^(7./4)*sqrt(pi)*dRH*(3*sqrt(D)-2*b*sqrt(s))*sqrt(-s./D)*(erfi1(sqrt(b)*(s./D).^(1./4))-erfi1(sqrt(r)*(s./D).^(1./4)))./(b.^(3./2)*s.^(9./4));
Error in ==> Egs at 25
y =
(1/k)*(a-b)*(a+b)*(Es/s)*D1*s*(b.^2*(nuc-1)-c.^2*(nuc+1))/(4*b.^2*(s*Epsf(s)-(s+lambda)*Epsf(s+lambda))+(b-c)*(b+c)*D1*((a.^2*(nus+1)-b.^2*(nus-1))));
Error in ==> Eg at 3
y = ilaplace(Egs(s),s,t);
Error in ==> graphe at 6
Ec = nu*Eg(t-tp);  
-------------
and here is the code
---------------
k=1.7;
lambda=0.3;
tp=1;
nu = k*(1-exp(-lambda*tp));
t  = 5:35;
Ec = nu*Eg(t-tp);
%graphe
plot(t,Ec)  
------------------
function ans=erfi1(t)
% %erfi(x). The Imaginary error function, as it is defined in Mathematica
% %erfi(z)==erf(iz)/i (z could be complex) using 
% %the incomplete gamma function in matlab: gammainc
% %Using "@": erfi = @(x) real(-sqrt(-1).*sign(x).*gammainc(-x.^2,1/2))
% %Note: limit(x->0) erfi(x)/x -> 2/sqrt(pi)
%
% %Example 1: 
% x=linspace(0.001,6,100);
% y=exp(-x.^2).*erfi(x)./2./x;
% figure(1), clf;plot(x,y*sqrt(pi))
%
% %Example 2: 
% [x,y]=meshgrid(linspace(-3,3,180),linspace(-3,3,180));
% z=x+i*y;
% figure(1), clf;contourf(x,y,log(erfi(z)))
% axis equal;axis off
xc=5.7;%cut for asymptotic approximation (when x is real)
it says that here is the error !
ans=~isreal(t).*(-(sqrt(-t.^2)./(t+isreal(t))).*gammainc(-t.^2,1/2))+...
  isreal(t).*real(-sqrt(-1).*sign(t).*((t<xc).*gammainc(-t.^2,1/2))+...
  (t>=xc).*exp(t.^2)./t/sqrt(pi));    
------------------------
function y = Epsf(s)
%constantes
a = 14;
b=15;
c=25;
L=c-b;
r=c;
phi=15;
V=7*7*28;
ro=1000;
RHi=100;
RHb=50;
dRH = RHb-RHi;
nus=0.3;
D=1;
M=8.3*10.^(-6);
k=1.7;
Es=200000;
nuc=0.2;
lambda=0.3;
tp=1;
nu = k*(1-exp(-lambda*tp));
%-------------
%RH(c,s)
  %Bi
        B1 = b*sqrt(s)./sqrt(D);
        B2 = c*sqrt(s)./sqrt(D);
        B3 = r*sqrt(s)./sqrt(D);
        B4 = -b*exp(B2)*(b-r)*(b+r)*RHi*sqrt(s)-3*c*exp(B2)*(b-r)*(b+r)*sqrt(s);
        B5 = D.^(7./4)*sqrt(pi)*dRH*(3*sqrt(D)-2*b*sqrt(s))*sqrt(-s./D)*(erfi1(sqrt(b)*(s./D).^(1./4))-erfi1(sqrt(r)*(s./D).^(1./4)))./(b.^(3./2)*s.^(9./4));
  RH= sqrt(D)*exp(-c*sqrt(s)./sqrt(D))*(-b*c*s./D).^(3./2)*((D).^(3./2)*sqrt(-  b*c*s./D)*(-6*c.^(3./2)*(sqrt(6*D)*exp(B1)-exp(B3)*sqrt(D*r))*dRH-  B4)./(b.^2*c.^2*s.^2)+B5)./(2*(3*c+b)*s.^(3./2));
  y = -1.1*M*((c.^2-b.^2)*RHi./(2*s)-RH);
-----------------------------------------------
  function y = Egs(s)
  %constantes
  a=14;
  b=15;
  c=25;
  L=c-b;
  r=c;
  phi=15;
  V=7*7*28;
  ro=1000;
  RHi=100;
  RHb=50;
  dRH = RHb-RHi;
  nus=0.3;
  D=1;
  M=8.3*10.^(-6);
  k=1.7;
  Es=200000;
  nuc=0.2;
  lambda=0.3;
  tp=1;
  nu = k*(1-exp(-lambda*tp));
  %------------------------
  D1 = s*Epssa(s)-(s+lambda)*Epssa(s+lambda)/exp(lambda*tp);
  y = (1/k)*(a-b)*(a+b)*(Es/s)*D1*s*(b.^2*(nuc-1)-c.^2*(nuc+1))/(4*b.^2*(s*Epsf(s)-(s+lambda)*Epsf(s+lambda))+(b-c)*(b+c)*D1*((a.^2*(nus+1)-b.^2*(nus-1))));
------------------------------------------------------
  function y = Eg(t)
  syms s;
  y = ilaplace(Egs(s),s,t);
--------------------------------
  function ans = Epssa(s)
  syms t;
  ans = laplace(Epsa(t),t,s);
-------------------------------
  function y = Epsa(t)
  y = -16.7*10.^(-6)*t.^(0.3);
--------------------------------
I really appreciate your help because I spent a lot of time in this issue :)

0 Comments

Mohamed Yassin OUKILA

Contact us