How to plot this code?

2 次查看(过去 30 天)
hosi
hosi 2023-7-10
评论: hosi 2023-7-10
Hey guys I've been trying to learn mathlab and I ended up writing this code the code below:
clc
close all;
clear
L=input("L= ");
Delta_a=input("Delta a= ");
W=input("W= ");
E=input("Modulus Yang= ");
I=input("I= ");
EI=E*I;
N=L/Delta_a;
n=0;
while n<N
a=n*Delta_a;
y1=(-W/(24*EI))*((a^4)-(4*L*(a^3)+(6*(L^2)*(a^2))));
Rd=((3*EI)/(L^3))*(y1);
tb1=(-W*(L^3))/(6*EI);
tb2=(Rd*(a^2))/(2*EI);
yb1=(-W*(L^4))/(8*EI);
yb2=((Rd*(a^3))/(3*EI))+((L-a)*tb2);
thetaB=tb1+tb2;
yB=yb1+yb2;
n=n+1;
if(n>N) end
fprintf('n= #%d\n', n);
fprintf('Reaction D= #%d\n', Rd);
fprintf('Shib= #%d\n', thetaB);
fprintf('Khamesh= #%d\n', yB);
end
So here is my question:
How can I plot yB on diffrent values of a?
My guess is to turn it into a matrix but I have no idea about how to that.

采纳的回答

N A POORNA CHANDRA
N A POORNA CHANDRA 2023-7-10
hi hosi , here is the code to plot yB on diffrent values of a?
i have assumed few hard coded values instead of taking them as input
clc
close all;
clear
L = 10; % Length (assumed value)
Delta_a = 0.5; % Delta a (assumed value)
W = 100; % W (assumed value)
E = 2e11; % Modulus of elasticity (assumed value)
I = 0.001; % I (assumed value)
EI = E * I;
N = L / Delta_a;
n = 0;
a_values = [];
yB_values = [];
while n < N
a = n * Delta_a;
y1 = (-W / (24 * EI)) * (a^4 - 4 * L * (a^3) + 6 * (L^2) * (a^2));
Rd = (3 * EI / (L^3)) * y1;
tb1 = (-W * (L^3)) / (6 * EI);
tb2 = (Rd * (a^2)) / (2 * EI);
yb1 = (-W * (L^4)) / (8 * EI);
yb2 = ((Rd * (a^3)) / (3 * EI)) + ((L - a) * tb2);
thetaB = tb1 + tb2;
yB = yb1 + yb2;
a_values = [a_values, a];
yB_values = [yB_values, yB];
n = n + 1;
end
plot(a_values, yB_values)
xlabel('a')
ylabel('yB')
title('Plot of yB against a')
grid on

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by