Help plotting function with i?
Mostrar comentarios más antiguos
Hello, I am trying to plot x and y from x = 0 to x=L. I was having trouble with it, but line y=funct... seems to have fixed it. However, I don't understand this part of the code. Can someone confirm that this is the way to do what I'm trying to do? Thank you
%constants
w0 =2.5 %kN/cm
L = 600 %cm
I = 30000 %cm^4
E = 50000; %kN/cm^2
x =linspace(0,L,100);
y = @(x) w0./(120*E*I*L)*(-5*x^4+6*L^2*x^2-L^4);
yfunc(i) = y(x(i));
plot(x,yfunc)
ylabel('Displacement [cm]')
xlabel('Location [cm]')
title('Max Deflection at x = 531.2241cm')
5 comentarios
Kevin Phung
el 18 de Sept. de 2019
can you post all of the code?
Rik
el 18 de Sept. de 2019
This syntax looks very odd. Unless i is a sym, or yfunc and i are arrays, I don't see how this is a valid syntax.
Raphael Hatami
el 18 de Sept. de 2019
dpb
el 18 de Sept. de 2019
Agreed...I suppose OP could have defined
i=1:numel(x);
and y is either an array of same or larger size or a function that can accept a vector. The latter, of course, would just be equivalent to writing
yfunc=y(x);
under that condition.
But, is most puzzling and peculiar and without the full code defining the other variables/functions, impossible to truly tell what's going on (or wrong).
Rik
el 18 de Sept. de 2019
The i variable is still undefined. If you don't define it, i is the imaginary unit, which would make indexing yfunc impossible. (yfunc is also undefined here)
When you create an example, check if it still runs if you put clearvars at the top.
Respuestas (0)
Categorías
Más información sobre Common Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!