how can you plot a matrix row vs row using a for loop

3 次查看(过去 30 天)
We were given 5 springs and had to put 3 different masses on each spring and then measure the displacement for each spring for each mass (3 masses & 3 displacements per spring).
% Masses for each Spring [g]: % 3 masses per spring
S1_M=[10 20 30];
S2_M=[20 30 50];
S3_M=[50 100 150];
S4_M=[100 200 300];
S5_M=[100 200 300];
% Displacement for each Spring [in]: % Displacements for each mass
S1_D=[1.35 2.95 4.45];
S2_D=[1.05 1.65 2.85];
S3_D=[1.1 2.55 3.9];
S4_D=[1.75 4.1 6.3];
S5_D=[1.25 2.9 4.45];
% Convert displacement from [in] to [m]:
S1_D=S1_D*0.0254;
S2_D=S2_D*0.0254;
S3_D=S3_D*0.0254;
S4_D=S4_D*0.0254;
S5_D=S5_D*0.0254;
% Convert mass[g] to force[N]:
S1_M=S1_M*0.0098;
S2_M=S2_M*0.0098;
S3_M=S3_M*0.0098;
S4_M=S4_M*0.0098;
S5_M=S5_M*0.0098;
% Create a single matrix for all 5 springs:
Disp=[S1_M;S1_D;S2_M;S2_D;S3_M;S3_D;S4_M;S4_D;S5_M;S5_D];
I know im right up until this point.
Then it says: in a function, use polyfit to determine the stiffness of each individual spring. Use a for loop within the function to accomplish these caculations. There are 5 springs and we are supposed to plot the force versus the displacement for each individual spring in a new figure. Below is how I started it, am I even doing this right?
? - means I don't know what variable to put there
% Create a for loop using polyfit to calculate the spring constants:
function[?]=?
[r,c]=size(Disp)
for i=1:1:r
for j=1:1:c %im missing the ployfit part
plot(Disp(?),Disp(?),'bo') in the for loop
end
end
  6 个评论
Daniel Shub
Daniel Shub 2013-3-8
You are essentially asking I to do your homework for you. That is not appreciated. Edit the question to show what you have tried, otherwise I will keep closing the question.
Will
Will 2013-3-8
Im sorry Daniel and Walter. I didnt know the policy and didnt mean to offend anyone. that was not my intentions at all. im stuck and dont know how to move on form here. i want nobody to do this for me. i just need help using polyfit to plot row vs row
sorry my my actions offending yal any help truly is greatly appreciated

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2013-3-8
编辑:Image Analyst 2013-3-8
Assuming you have one mass at a time hanging vertically down, where the other end of the spring is attached to the ceiling, you can say force = k*distance = mass*acceleration = mass*g. So k = force / distance. You have the force and you have the distance so you just need to make up the 3 k's I would guess. Though I don't know why you need polyfit instead of just averaging the 3 k's. Then you do that for each of the 5 springs.
  13 个评论
Will
Will 2013-3-8
SP=spring M=mass(Force) D=Displacement
the problem says the format of the matrix has to be:
SP1-M1 SP1-M2 SP1-M3
SP1-D1 SP1-D2 SP1-D3
SP2-M1 SP2-M2 SP2-M3
SP2-D1 SP2-D2 SP2-D3
etc for each spring %i need to plot row 1vs2,3vs4,5vs6,etc
Image Analyst
Image Analyst 2013-3-10
So it's been a few days. I assume it's done by now, right?

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by