How can I plot this anonymous function?

w0 = 200;
E = 200000;
I = 250.9*10^.6;
L = 6;
deflection = @(x) (w0/(120*E*I*L)).*(-(x.^5) + 2*(L.^2)*(x^.3) - (L.^4)*x);
rotation = @(x) (w0/(120*E*I*L)).*(-5*(x.^4) + 6*(L.^2)*(x^.2) - (L.^4));
derivofrotation = @(x) (w0/(120*E*I*L)).*(-20*(x.^3) + 12*(L.^2)*(x));
plot(x, rotation(x))
This is my code. When I run wihhout the plot function it raises no errors. When the plot is there the following errors are raised:
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power.
Check that the matrix is square and the power is a
scalar. To perform elementwise matrix powers, use '.^'.
Error in
MATLAB_MAJOR>@(x)(w0/(120*E*I*L)).*(-5*(x.^4)+6*(L.^2)*(x^.2)-(L.^4))
(line 8)
rotation = @(x) (w0/(120*E*I*L)).*(-5*(x.^4) +6*(L.^2)*(x^.2) - (L.^4));
Error in MATLAB_MAJOR (line 14)
plot(x, rotation(x))
Why are these errors coming up and what can I do to stop them?

 採用された回答

Steven Lord
Steven Lord 2020 年 10 月 17 日

0 投票

(x^.2)
You probably don't want to use the matrix power operator ^ to raise the square matrix x to the 0.2 power here. You probably want to raise each element of x to the 2nd power.
(x.^2)

1 件のコメント

Isaac Gautreau
Isaac Gautreau 2020 年 10 月 17 日
Yes thank you! I messed up the order!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

製品

リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by