??? Error using ==> mtimes Inner matrix dimensions must agree. Error in ==> Untitled2 at 16 l0=[(x-15)*(x-25)*(x-35)*(x-45)]/240000;
Mostrar comentarios más antiguos
x=(0:1:40);
l0=((x-15)*(x-25)*(x-35)*(x-45))/240000;
l1=-(((x-5)).*((x-25)).*((x-35))*((x-45)))/60000;
l2=((x-5)*(x-15)*(x-35)*(x-45))/40000;
l3=-((x-5)*(x-15)*(x-25)*(x-45))/60000;
l4=((x-5)*(x-15)*(x-25)*(x-35))/240000;
plot(x,l0,'b',x,l1,'r',x,l2,'y',x,l3,'g',x,l4,'m')
Respuestas (2)
James Tursa
el 18 de Nov. de 2015
Editada: James Tursa
el 18 de Nov. de 2015
Change the matrix operator * to element-wise operator .*
E.g.,
x=(0:1:40);
l0 = ((x-15).*(x-25).*(x-35).*(x-45))/240000;
l1 = -(((x-5)).*((x-25)).*((x-35)).*((x-45)))/60000;
l2 = ((x-5).*(x-15).*(x-35).*(x-45))/40000;
l3 = -((x-5).*(x-15).*(x-25).*(x-45))/60000;
l4 = ((x-5).*(x-15).*(x-25).*(x-35))/240000;
Star Strider
el 18 de Nov. de 2015
You need to vectorise all operations in your calculations.
For example:
l0=((x-15).*(x-25).*(x-35).*(x-45))/240000;
I would have preferred that you had named your variables starting with something other than a lower-case ‘l’, since it can be confused with 1.
Categorías
Más información sobre Matrix Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!