Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.8K Views
|
10 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Clean up output from FindRoot?

Posted 6 years ago

See attached sample code for my issue:

Cleaning up junk output 1000 -> from running FindRoot in a process.

This topic has been posted and answered many times, here, and elsewhere, but still I cannot get it to work and plot this graph. No doubt, I'm missing one strategically placed symbol somewhere in the code. G

Attachments:
POSTED BY: Gerald Proteau
10 Replies
Posted 6 years ago

Hi Gerald,

The functions defined have no formal arguments. Since x is bound to .3, the function will return the same value for any argument passed to it.

x = .3;
outlayer = Function[a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4];
outlayer[2]
(* a0 + 0.3 a1 + 0.09 a2 + 0.027 a3 + 0.0081 a4 *)
outlayer[1] == outlayer[2]
(* True *)

Provide a formal argument or use SetDelayed.

ClearAll[outlayer];
outlayer = Function[x, a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4];
outlayer[2]
(* a0 + 2 a1 + 4 a2 + 8 a3 + 16 a4 *)

ClearAll[outlayer];
outlayer[x_] := a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4;
outlayer[2]
(* a0 + 2 a1 + 4 a2 + 8 a3 + 16 a4 *)

If you are new to WL, take a look at this and this.

POSTED BY: Rohit Namjoshi
Posted 6 years ago
POSTED BY: Bill Nelson
Posted 6 years ago

I like the way you've arranged it, from past practice I've been coding one item per row but this is more organized. Perhaps IF I get what i want working, I'll come back and tidy up.

Why does MM complain about simple polynomial functions such as these? I have about a dozen 4th order polynomials to define, and they all are a function of x. x=.3 outlayer=Function[a0+a1* x+a2* x^2+a3* x^3+a4* x^4] inlayer=Function[b0+b1* x+b2* x^2+b3* x^3+b4* x^4]

One of the definitions is shadowed, in this case x is. Can this be ignored?

POSTED BY: Gerald Proteau
Posted 6 years ago

I don't know whether you want to get into reorganizing the code or not.

This might be a little simpler in some ways and appears to produce exactly the same result.

spn=1000; w=1.093; tareacable=0.005044; initialslack=0.01; strainlimub=0.5;
strainincrement=0.1; iters=(spn*strainlimub-200*initialslack)/(100*strainincrement)+1;
slack=initialslack-strainincrement;
ListPlot[Table[
  slack=slack+strainincrement; 
  {slack/spn*100,
   H/.FindRoot[{((2*(H/w)*Sinh[spn*w/(2*H)]-spn-slack)/tareacable)},{H,1000}]
  },{iters}
]]
POSTED BY: Bill Nelson
Posted 6 years ago

Thanks much. I had reviewed use of /. prior to posting but did not make the connection the variable name is referred to rather than just the output.(which almost works btw)

G

POSTED BY: Gerald Proteau

I have tried a rather "silly" method: elongation1 = Thread[Transpose[ Thread[{slacdataStrain, Flatten[slacdataTension]}]] /. KeyValuePattern[{H -> x1, H -> x2, H -> x3, H -> x4, H -> x5, H -> x6, H -> x7, H -> x8, H -> x9, H -> x10, H -> x11, H -> x12, H -> x13, H -> x14, H -> x15, H -> x16, H -> x17, H -> x18, H -> x19, H -> x20, H -> x21, H -> x22, H -> x23, H -> x24, H -> x25_}] -> {x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20 , x21, x22, x23, x24, x25}]

And then Plot it: In[279]:= ListPlot[elongation1, Joined -> True]

Attachments:
Posted 6 years ago

Try replacing

slacdataTension[[i]]=FindRoot[{((2*(H/w)*Sinh[spn*w/(2*H)]-spn-slack)/tareacable)},{H,1000}];

with

slacdataTension[[i]]=H/.FindRoot[{((2*(H/w)*Sinh[spn*w/(2*H)]-spn-slack)/tareacable)},{H,1000}];

which will remove all the H-> in your results and let you see your plot. You can search for /. in the help pages and see if that helps explain what this change does.

POSTED BY: Bill Nelson
Posted 6 years ago

Thanks for taking the time to review. I've updated the attached file to show exactly what I've mentioned in my first post. The second file is a screenshot from Prime 3.1 with the same process and variables. The two outputs agree and the output is as expected, so I don't think at any of the increments the program fails to converge but that said I'm not that familiar yet with Mathematica's warnings on precision. The plot, and eventually to be a manipulated plot I wish to prepare shows a transmission line stranded cable horizontal tension H as a function of strain in a suspended catenary. G

Attachment

Attachments:
POSTED BY: Gerald Proteau
Posted 6 years ago

Check this carefully

spn=1000; w=1.093; tareacable=0.005044; initialslack=0.01; strainlimub=0.5;
strainincrement=0.1; slack=initialslack;
iters=(spn*strainlimub-200*initialslack)/(100*strainincrement)+1;
i=1;slacdataStrain=Table[0,{i,1,iters}]; slacdataTension=Table[0,{i,1,iters}];
While[(slack/spn)*100<strainlimub,
  slacdataStrain[[i]]= slack/spn*100; 
  slacdataTension[[i]]=H/.FindRoot[{((2*(H/w)*Sinh[spn*w/(2*H)]-spn-slack)/tareacable)},{H,1000}]; 
  slack=slack+strainincrement; 
  i++];
points=Transpose[{slacdataStrain,slacdataTension}];
ListPlot[points]

There are a number of warning messages printed which may indicate that no sufficiently precise roots were able to be found for some values of your parameters.

POSTED BY: Bill Nelson
Posted 6 years ago

Hi Gerald,

Not sure what you mean by "Cleaning up junk output 1000 ->". When I run the code in the attached notebook, right after the While

slacdataTension
(*
{{H -> 70553.}, {H -> 21272.8}, {H -> 15396.4}, {H -> 12672.3}, {H -> 
   11019.2}, {H -> 9880.13}, {H -> 9034.19}, {H -> 8373.97}, {H -> 
   7840.16}, {H -> 7396.96}, {H -> 7021.33}, {H -> 6697.69}, {H -> 
   6415.06}, {H -> 6165.44}, {H -> 5942.88}, {H -> 5742.81}, {H -> 
   5561.69}, {H -> 5396.69}, {H -> 5245.57}, {H -> 5106.49}, {H -> 
   4977.91}, {H -> 4858.59}, {H -> 4747.47}, {H -> 4643.64}, {H -> 
   4546.35}, {H -> 4454.93}, {H -> 4368.82}, {H -> 4287.52}, {H -> 
   4210.6}, {H -> 4137.69}, {H -> 4068.43}, {H -> 4002.55}, {H -> 
   3939.77}, {H -> 3879.86}, {H -> 3822.6}, {H -> 3767.81}, {H -> 
   3715.32}, {H -> 3664.96}, {H -> 3616.6}, {H -> 3570.1}, {H -> 
   3525.36}, {H -> 3482.26}, {H -> 3440.7}, {H -> 3400.61}, {H -> 
   3361.88}, {H -> 3324.45}, {H -> 3288.24}, {H -> 3253.2}, {H -> 
   3219.25}, {H -> 3186.35}}
*)

I don't see any "1000 ->".

Also not sure what you are trying to plot. The attached notbook does not have any plotting related code.

$Version (* 12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019) *)

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard