Help plotting function with i?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2019-9-18
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
2019-9-18
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.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!