??? Error using ==> mtimes Inner matrix dimensions must agree. Error in ==> Untitled2 at 16 l0=[(x-15)*(x-25)*(x-35)*(x-45)]/240000;
Show older comments
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')
Answers (2)
James Tursa
on 18 Nov 2015
Edited: James Tursa
on 18 Nov 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
on 18 Nov 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.
Categories
Find more on Matrix Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!