error using multiplication, incorrect dimensions

I get an error that says error using * in lines 18 and 19, I can't quite seem to figure out where the correction is to be! anything helps! thanks
delta = 0.05;
p = 0.85;
v = 0.05;
y = [0 0.50 2.5];
u = 0.02;
I = 6000000;
t = [0 10 100];
c0 = 95000000;
n0 = 112000000;
e = 1;
theta = y + u + v + delta;
s = p + theta + u;
b = p*v + p*delta + p*u + u*theta;
a = 2*p + u;
n1 = 1/2*(s - sqrt(s.^2 - 4*b));
n2 = 1/2*(s + sqrt(s.^2 - 4*b));
k1 = ((b*(p+theta-n2)*c0+I*(a*n2-b)-(p*b*n0))/(b*(n1-n2)));
k2 = ((-b*(p+theta-n1)*c0+I*(b-a*n2)-(p*b*n0))/(b*(n1-n2)));
c_t = k1*e.^(-n1*t) + k2*e.^(-n2*t)+(a/b)*I;
plot (t, c_t);

回答(1 个)

There are vectors in those equations, so maybe you just need to use element-wise operations:
k1 = ((b.*(p+theta-n2).*c0+I.*(a.*n2-b)-(p.*b.*n0))./(b.*(n1-n2)));
k2 = ((-b.*(p+theta-n1).*c0+I.*(b-a.*n2)-(p.*b.*n0))./(b.*(n1-n2)));

类别

帮助中心File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by