MATLAB Answers

Ploting an anonymous function

2 views (last 30 days)
Mulanga Forgiveness Mulanga
Mulanga Forgiveness Mulanga on 24 Oct 2020 at 22:50
Answered: Star Strider on 24 Oct 2020 at 22:59
I an trying to plot this graph :
M_a = mb*g*2 - Cw*rIntegral*y_bar
Cw = 0.5*rho*(v^2)*(1/yr^0.286)*(rb+rt)*(h/2)*0.2 % Wind force constant;
c1 = ((rt-rb)/h)^2;
c2 = ((rt-rb)/h)*rb;
c3 = rb^2;
y = linspace(0,h);
M1 = (y) M_a + 2*Cw((c1/4.286)*(y.^(4.286)) + (2*c2/3.286)*(y.^(3.286)) + (c3/2.286)*(y.^(2.286))) - F_ax*y;
plot(y,M1(y))
and it gives me this error:
"Array indices must be positive integers or logical values. Error in MatLab_2020 (line 36)
M1 = @ (y) + 2*Cw((c1/4.286).*(y.^(4.286)) + (2*c2/3.286).*(y.^(3.286)) + (c3/2.286).*(y.^(2.286))) - F_ax.*y;"

  0 Comments

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 24 Oct 2020 at 22:59
It appears that ‘Cw’ also needs to be an anonymous funciton, however it is absolutely not obvious what variable it supposed to be a function of.
So:
M_a = mb*g*2 - Cw*rIntegral*y_bar
Cw = @(something) 0.5*rho*(v^2)*(1/yr^0.286)*(rb+rt)*(h/2)*0.2 % Wind force constant;
c1 = ((rt-rb)/h)^2;
c2 = ((rt-rb)/h)*rb;
c3 = rb^2;
y = linspace(0,h);
M1 = (y) M_a + 2*Cw((c1/4.286)*(y.^(4.286)) + (2*c2/3.286)*(y.^(3.286)) + (c3/2.286)*(y.^(2.286))) - F_ax*y;
plot(y,M1(y))
It will aso be necessary to vectorise it, since it and ‘M1’ appear to be a functions of a vector. See Array vs. Matrix Operations for details.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!