Error in MuPAD command: The dimensions do not match

1 Ansicht (letzte 30 Tage)
PIERLUIGI PEDERZOLI
PIERLUIGI PEDERZOLI am 20 Jul. 2015
Hi, I have to do a for cicle in which one variable (k) change and the others variables are costants, but Matlab gives me an error: Error in MuPAD command: The dimensions do not match. I am trying to use the following code (I'm sorry for the length of the equation) to obtain a vectors of results. Then I want to plot KAP as function of k:
syms F x c k
KAP=(F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k^2*exp(-k*(F + c - x))*(F*exp(-x) - 1) - F*exp(-k*(F + c - x))*exp(-x) + 2*F*k*exp(-k*(F + c - x))*exp(-x) + F*k^2*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1)^2 + 2*F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1))/(k*exp(-k*(F + c - x))*(F*exp(-x) - 1) + F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - F*exp(-k*(F + c - x))*exp(-x) + F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1))
k=0.1:0.1:0.6
for i=1:length(k)
KAP=(F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k^2*exp(-k*(F + c - x))*(F*exp(-x) - 1) - F*exp(-k*(F + c - x))*exp(-x) + 2*F*k*exp(-k*(F + c - x))*exp(-x) + F*k^2*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1)^2 + 2*F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1))/(k*exp(-k*(F + c - x))*(F*exp(-x) - 1) + F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - F*exp(-k*(F + c - x))*exp(-x) + F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1))
KAP=subs(KAP,{F,x,c,k(i)},{5,4,4,0.1})
KAP=vpa(KAP)
end
Variables like F, x, c have to be constant. Anyone could help me?

Antworten (3)

Walter Roberson
Walter Roberson am 20 Jul. 2015
syms F x c k
KAPeqn = (F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k^2*exp(-k*(F + c - x))*(F*exp(-x) - 1) - F*exp(-k*(F + c - x))*exp(-x) + 2*F*k*exp(-k*(F + c - x))*exp(-x) + F*k^2*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1)^2 + 2*F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1))/(k*exp(-k*(F + c - x))*(F*exp(-x) - 1) + F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - F*exp(-k*(F + c - x))*exp(-x) + F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1));
kvals = 0.1:0.1:0.6;
for i = 1 : length(kvals)
KAP(i) = vpa(subs(KAPeqn,{F,x,c,k},{5,4,4,kvals(i)}));
end
plot(kvals, KAP);

PIERLUIGI PEDERZOLI
PIERLUIGI PEDERZOLI am 20 Jul. 2015
Thanks a lot. Now it works well. How can I see all the steps of the scripts in the command window with the numeric value that KAPeqn assumes when k change?
  1 Kommentar
Walter Roberson
Walter Roberson am 20 Jul. 2015
syms F x c k
KAPeqn = (F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k^2*exp(-k*(F + c - x))*(F*exp(-x) - 1) - F*exp(-k*(F + c - x))*exp(-x) + 2*F*k*exp(-k*(F + c - x))*exp(-x) + F*k^2*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1)^2 + 2*F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1))/(k*exp(-k*(F + c - x))*(F*exp(-x) - 1) + F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - F*exp(-k*(F + c - x))*exp(-x) + F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1));
kvals = 0.1:0.1:0.6;
for i = 1 : length(kvals)
KAPi = vpa(subs(KAPeqn,{F,x,c,k},{5,4,4,kvals(i)}))
KAP(i) = KAPi;
end
plot(kvals, KAP);

Melden Sie sich an, um zu kommentieren.


PIERLUIGI PEDERZOLI
PIERLUIGI PEDERZOLI am 21 Jul. 2015
Again thank you!

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by