How can I plot this anonymous function?

4 vues (au cours des 30 derniers jours)
Isaac Gautreau
Isaac Gautreau le 17 Oct 2020
Commenté : Isaac Gautreau le 17 Oct 2020
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?

Réponse acceptée

Steven Lord
Steven Lord le 17 Oct 2020
(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 commentaire
Isaac Gautreau
Isaac Gautreau le 17 Oct 2020
Yes thank you! I messed up the order!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by