Error correction...inner matrix dimensions must be same??? how to correct ?

[EDIT: 20110610 00:25 CDT - reformat - WDR]
I wrote the following code:
------------------------
w=10:2:30;
a=4*((9*w)-7);
b=(-2)*((18*w)-16)*(w+1);
c=3*((w+1)^2)*((3*w)-1);
d=(-3)*((1+w)^3);
f = roots([a,b,c,d]);
f=f(f<1);
ptr=2./(1+w);
u=(1+w)./2;
l=(u*(1-ptr*f)^3)./3;
plot(w,l);
--------------------------
It shows the following error:
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> cubic at 3
b=(-2)*((18*w)-16)*(w+1);
======================
I am not able to correct it .Please help........

 採用された回答

Walter Roberson
Walter Roberson 2011 年 2 月 28 日

0 投票

There are significant difficulties with the code that are being explored in the thread about cubic roots. Please do not spread the discussion over two threads.

その他の回答 (1 件)

Matt Fig
Matt Fig 2011 年 2 月 28 日

1 投票

You must put a dot before any *, / or ^ used when you want element-by-element operations on arrays of the same size. Note that if the arrays are not of the same size (or scalar), all bets are off.
A.*B
A./B
A.^B
Also, look at your other post (about cubic roots), I showed you this there too.

3 件のコメント

Bhagat
Bhagat 2011 年 2 月 28 日
w=10:2:30;
a=4*((9*w)-7);
b=(-2)*((18*w)-16).*(w+1);
c=3*((w+1).^2).*((3*w)-1);
d=(-3)*((1+w).^3);
f = roots([a,b,c,d]);
f=f(f<1);
ptr=2./(1+w);
u=(1+w)./2;
l=(u.*(1-(ptr.*f).^3))./3;
plot(w,l);
============================
In the above code following error is coming:
??? Error using ==> times
Matrix dimensions must agree.
Error in ==> cubic at 10
l=(u.*(1-(ptr.*f).^3))./3;
==================================
How and which matrix dimensions don't agree here ???
Sean de Wolski
Sean de Wolski 2011 年 2 月 28 日
{u, pte, f} must all be the same size or scalar
Matt Fig
Matt Fig 2011 年 2 月 28 日
Did you look at the other post? You keep posting the same erroneous code over and over, but did you try what I wrote in the other post???? I ran it and got no errors.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by