For Loop answer into a vector
4 次查看(过去 30 天)
显示 更早的评论
See my code below. I want to run a for loop that will loop through the eqn y 20 times with the value of x that is gotten from the linspace.
Then i want to save each value of y from the loop, into a vector. Can someone help me please. Hope that makes sense.
clc, clear all, close all
b = 10;
d = 10;
E = 207E9;
p = -8000;
I = (b*d^3)/12;
l = 227;
x = linspace(1,226,20);
for i = 1:length(x)
y = (p*x^2*(3*l-x)/(6*E*I))
end
1 个评论
David Hill
2021-9-29
b = 10;
d = 10;
E = 207E9;
p = -8000;
I = (b*d^3)/12;
l = 227;
x = linspace(1,226,20);
y = (p.*(x.^2).*(3*l-x)./(6*E*I));
采纳的回答
Dave B
2021-9-29
b = 10;
d = 10;
E = 207E9;
p = -8000;
I = (b*d^3)/12;
l = 227;
x = linspace(1,226,20);
% not necessary, but good:
y = nan(size(x));
for i = 1:length(x)
y(i) = (p*x(i)^2*(3*l-x(i))/(6*E*I));
end
disp(y)
% But you didn't need the for loop, you should just do it the MATLAB way!
y = (p.*x.^2.*(3*l-x)/(6*E*I));
disp(y)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!