Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scaling of a matrix by a given length

Status
Not open for further replies.

dario87ct

Mechanical
Jan 6, 2012
4
Hi,I'm not an expert user of Matlab. I'm having some issues in a scaling procedure in Matlab. Here's the problem:

I've a matrix 2xN(called TR2) of x and y coordinates of an arc. I want to scale the y values (2nd row) by imposing that the length of the computed arc (arc_l) is equal (or really close to) to the real given length l_f.

I've done this by a while loop within an if condition. This script seems to work only when arc_l < l_f, while it doesn't work in the opposite case.

Can someone give me any adviceon how to solve it?

Here is the TR2 matrix (TR2 is the transposed matrix of the one pasted in here! [2 X 51] and the code:

0 0
-143.642227990181 -25.8371011638989
-281.905431126358 -50.5364770431188
-443.884238501258 -78.7603563152049
-611.940005943982 -107.262483743439
-770.171516623216 -133.632334671524
-941.902183372010 -161.127906887307
-1111.22277702901 -187.509565809469
-1291.42317851041 -214.272542171579
-1471.71190796770 -239.955853568353
-1654.53905519843 -264.704298652706
-1839.14009186069 -288.332963189761
-2022.91770486443 -310.472556300275
-2209.09488529637 -331.269976393350
-2397.24075762224 -350.692693311921
-2586.06438645260 -368.546199238336
-2773.84658460458 -384.687527428108
-2959.93097208808 -399.302059653846
-3147.56317001033 -412.248952763568
-3336.86067659113 -423.619215674472
-3523.53838997676 -433.671735152732
-3708.64785195090 -441.943785972255
-3894.34658338634 -448.318035617962
-4080.32616798848 -453.226829546078
-4265.54945806981 -456.504310804198
-4450.33147420291 -458.250041596867
-4635.01862771767 -458.757630400473
-4819.68793730810 -457.628057466987
-5003.90500185717 -454.666254359758
-5187.25828988660 -449.842839426198
-5370.07473503580 -443.465445593576
-5552.73250393429 -435.755938930108
-5735.18671384945 -426.563044754289
-5917.11624510613 -415.679018368171
-6098.64465222180 -403.163598276472
-6279.76698993052 -389.137843781867
-6459.77647596105 -373.512190966579
-6638.17790995918 -356.194242888181
-6816.71150221742 -337.559000377828
-6994.57968656104 -317.329695350117
-7171.06257587543 -295.388764711130
-7347.93964786731 -272.289529931392
-7523.56324900350 -247.700743215882
-7696.04358347039 -221.235103511017
-7866.42306854668 -193.091424150058
-8040.35809417195 -164.407740930077
-8217.17808177125 -135.061476502330
-8393.08763314449 -104.249451317356
-8564.05656718544 -71.5464913099327

l_f = 6240;

arc_l = 0;
for k = 2:N
arc_l = arc_l + sqrt((TR2(1, k-1) - TR2(1, k))^2 + (TR2(2, k-1) - TR2(2, k))^2);
end

if arc_l < l_f

while arc_l < l_f

TR2(2, :) = TR2(2, :) * (l_f/(arc_l));

arc_l = 0;
for m = 2:N
arc_l = arc_l + sqrt((TR2(1, m-1) - TR2(1, m))^2 + (TR2(2, m-1)...
- TR2(2, m))^2)
end
end
arc_l2 = arc_l;

elseif arc_l > l_f

while arc_l > l_f

TR2(2, :) = TR2(2, :) * (l_f/(arc_l));

arc_l = 0;
for m = 2:N
arc_l = arc_l + sqrt((TR2(1, m-1) - TR2(1, m))^2 + (TR2(2, m-1)...
- TR2(2, m))^2);
end
end
end


Thanks

Dario

 
Replies continue below

Recommended for you

I spent a few more minutes looking at what you were trying to do. Perhaps this will give you the desired result:
Code:
x = linspace(-8564.1,0);
y = polyval([2.3109e-005 0.2083 11.8645],x);
TR2 = [x',y'];
l_f = 6240;
arclength  = sum(sqrt(diff(TR2(:,1)).^2+diff(TR2(:,2)).^2));
scaled_TR2 = [TR2(:,1), TR2(:,2).*l_f/arclength];

Hope that helps. Good luck.
 
Hi Christopher,

thank you for your help.

I don't understand how did you get the polinomial coeff [2.3109e-005 0.2083 11.8645] and if they allow to mantain the same "shape" of the vector y (note that the x and y vectors represents a 2D section of a sail, thus the aim of the scaling is just to make this section more or less "fat".

Moreover I made your code run and compute the arclength after the scaling, but it is still far from the desired value of 6240 (this equality is the aim of this script)

Cheers

Dario
 
There is a major problem with your problem as posed. The distance along the x-axis is 8564, which is longer than your desired length. Therefore, it is impossible to achieve the desired length by scaling only the y-value. Had you bothered to verify the problem in Excel, it would have been immediately obvious.

This leads me to suspect that this is a homework posting.

TTFN
faq731-376
7ofakss
 
Hi. This is not an homework.

It is really silly but I didn't note it. Thanks for telling me. Of course it explains why the loop (while arc_l > l_f) never ends in cases like this one.
I have to implement another kind of scaling when the x-axis distance is too high.

Cheers

Dario
 
The most obvious question is why not always scale both.

TTFN
faq731-376
7ofakss
 
It is not that easy to answer. I try to summarize. The figure should help.

I'm trying to reproduce numerically the shape of an entire sail starting from the knoledge of the shape (x,y,z, coordinates) three stripes (empty dots in the picture). This piece of code deals with the determination of the bottom of the two sails.

I did it all through a series of interpolation (mainly using the interp1 command of matlab), given some dimensions of the sail.

For the mainsail (the one in the left of the picture) I know the x position of the last point in the left-bottom (called clew). Thus simply by interpolating I can obtain a correct x-axis distribution of the points, and then I adjust the y values through this code.

For the jib (on the right) is not that easy as I don't know the position of the last point ("clew"). I can determine the z coordinate of the clew by the knowledge of some sail dimensions (of course it is an approximated value, not the exact one).Then I decided (but this is my choice) to find the x-coordinates by simply interpolating x values from the other stripes, and then to adjust the y values like I did for the other sail.

Probably this is not the best way to do it, but by now I don't see any better solution. The case that I posted is an example in which this kind of interpolation is not working properly, as it leads to an excessive foot dimensions.

Maybe I could try to scale both values, and see if it leads to a better solution.

I hope that I've been clear enough, I tried to be not too specific to avoid confusion.

 
 http://files.engineering.com/getfile.aspx?folder=c7406322-3d6d-4baf-83a4-92839ef33f3c&file=sail.jpg
Dario,
The polynomial is merely a curve-fit to the data you posted. I thought it would be more compact to display it in that way.

-Chris
 
I guess I don't understand your starting point. Your sail length should be nearly constant and known, unless the material is very stretchy. The fact that your algorithm results in a different length would indicate to me that there is a fundamental flaw in the approach. This is compounded by the fact that the typical shape of the sail is not constant.

Moreover, I think the pressure distribution likewise indicates differing profiles along the height of the sail.

TTFN
faq731-376
7ofakss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor