Error in MuPAD command: The dimensions do not match

1 visualizzazione (ultimi 30 giorni)
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?

Risposte (3)

Walter Roberson
Walter Roberson il 20 Lug 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 il 20 Lug 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 Commento
Walter Roberson
Walter Roberson il 20 Lug 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);

Accedi per commentare.


PIERLUIGI PEDERZOLI
PIERLUIGI PEDERZOLI il 21 Lug 2015
Again thank you!

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by