Filter löschen
Filter löschen

Help plotting function with i?

1 Ansicht (letzte 30 Tage)
Raphael Hatami
Raphael Hatami am 18 Sep. 2019
Kommentiert: Rik am 18 Sep. 2019
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 Kommentare
dpb
dpb am 18 Sep. 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
Rik am 18 Sep. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by