clc;clear all;
l=25;
E=200e9;
I=350e-6;
w=6e3;
for x=linspace(0,l/2,25)
y=(-(w*x)/(384*E*I))*(16*(x^3)-24*l*(x^2)+9*(l^3))
end
for x=linspace(l/2,l,26)
y=(-(w*x)/(384*E*I))*(8*(x^3)-24*l*(x^2)+17*x*(l^2)-(l^3))
end
figure
plot(x,y)

 Akzeptierte Antwort

Image Analyst
Image Analyst am 26 Nov. 2014

0 Stimmen

If you're absolutely required to use a for loop, just add an index to y
% Clean up
close all;
clc;
clear all;
l=25;
E=200e9;
I=350e-6;
w=6e3;
x1=linspace(0,l/2,25)
for k = 1 : length(x1)
y1(k)=(-(w*x1(k))/(384*E*I))*(16*(x1(k)^3)-24*l*(x1(k)^2)+9*(l^3))
end
x2=linspace(l/2,l,26)
for k = 1 : length(x2)
y2(k)=(-(w*x2(k))/(384*E*I))*(8*(x2(k)^3)-24*l*(x2(k)^2)+17*x2(k)*(l^2)-(l^3))
end
x = [x1, x2];
y = [y1, y2];
plot(x,y, 'bo-')
grid on;

2 Kommentare

ernest
ernest am 26 Nov. 2014
thank you so much! is it possible if i could get your contact for some other questions?
Image Analyst
Image Analyst am 26 Nov. 2014
I'm always here but I don't always have the best ideas so post here and get multiple good ideas you can choose from. You can't get that with a private side discussion with one person. Thanks for accepting though!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Thorsten
Thorsten am 26 Nov. 2014

0 Stimmen

Because your y is just a single point. Work on the whole vector and make sure to use .*, ./ and .^ when you want point-wise operation.
l=25;E=200e9;I=350e-6;w=6e3;
x=linspace(0,l/2,25); y=(-(w*x)/(384*E*I)).*(16*(x.^3)-24*l*(x.^2)+9*(l^3)) ;
plot(x, y, 'b')
hold on
x=linspace(l/2,l,26); y=(-(w*x)/(384*E*I)).*(8*(x.^3)-24*l*(x.^2)+17*x*(l^2)-(l^3));
hold on
plot(x, y, 'r')

1 Kommentar

ernest
ernest am 26 Nov. 2014
the question require me to use a loop operation,followed by an array operation. help please!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by