Total Format - Total Entertainment
 
 

Go Back   Total Format Forum > Computing Forums > Coding, Design & Graphics

Coding, Design & Graphics If you are programming a script, designing a web page, building your own graphics or anything related and need to discuss it, get help and tips or general advice, then you should post your thoughts to this section.

Reply
 
LinkBack Thread Tools Display Modes
Old 24-05-2009, 01:52   #1 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,205
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,762.87
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default x=y^y so, given x how to find y ?

say we have x which for example is 10000, then how to find a value y
so that y^y = 10000 ?

(thats y to the power of y)

x can be any number from about 10 to 1000000

I don't know if it can be done directly so i had to use an iteration loop, where you start off with a guess, then look at the error, then move the guess in (hopefully) the correct direction by an amount that doesn't make the error bigger.

well Ive come up with a very surprisingly good way of moving the guess that comes close to doing it in one go, but for the life of me I cant think why it is so close, can any one shed any light on this ?

n=3; // <- good place to start

...loop
x2=n^n;
...check error and break if good
n=n+Log10(x/x2)
..rinse and repeat
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Tools meow is online now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 24-05-2009, 15:28   #2 (permalink)
Name, Title, Location Ixpah
Full Member

Nottingham, UK
England
AvatarIxpah's Avatar
Mood
Posts335
Karma Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.
Pu8,096.80
Default

No idea, but look at:
http://www24.wolframalpha.com/input/?i=x%3Dy^y

it never was supposed to be a search engine, but its good at maths.

y = (log(x))/(W(log(x)))

although I didn't follow exactly what the W() function did, something about product log function.
Ixpah's Sig:Check out my forums @ zints.co.uk or My Blog
ToolsIxpah is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 24-05-2009, 17:51   #3 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,205
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,762.87
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default

cool, but it seems the W function is just as difficult to calculate.

Lambert W function - Wikipedia, the free encyclopedia

I think i was quite lucky in working out the next step, to start with i used this as it made sense...

n=3;
//start of loop
n1=Pow(x,1/n); //n1=nth root of x
n=n +(n-n1)/k;

this relies on the result is defiantly going to be in between n and the nth root of x.
where k seemed to be good at about 3.

I cant find any way of deriving how the function i used is so good,
also usually you can use log10 and natural logs interchangeably,
however my solution requires log10, wheres as many places need logn if they need a particular base.
maybe base 10 might be not be the optimum, however although this works good
its quite interesting trying to work out why,,,

maybe Ive stumbled on something new !

Last edited by meow; 24-05-2009 at 18:43..
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Tools meow is online now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 25-05-2009, 11:38   #4 (permalink)
Name, Title, Location Ixpah
Full Member

Nottingham, UK
England
AvatarIxpah's Avatar
Mood
Posts335
Karma Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.
Pu8,096.80
Default

That article has got 2 code sample which could easily be converted to whatever language you are using, plus if you are using a maths library surely its got the function anyway.

"something new"... probably not.
Ixpah's Sig:Check out my forums @ zints.co.uk or My Blog
ToolsIxpah is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 25-05-2009, 13:18   #5 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,205
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,762.87
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default

yeah , i looked for W but c# .net doesnt seem to have it.
I looked at the iterative routines for W but my code is simpler,
only 2 functions to call per loop
and i did work out the performance of it,

for an initial gues of y=3
if y is realy 2 ie x=4 then the actual error is -1, log x1/x2 is -.77
if y is realy 4 ie x=256 then the actual error is +1, log x1/x2 is +.976 which is quite close
if y is realy 5 ie x=3125 then the actual error is +2 , log x1/x2 is 2.06 which is very close
if y is realy 6 ie x=46656 then the actual error is +3, log x1/x2 is 3.2


I think the wolfram site is realy good , i think thats were ive found my most usefull source of 3d maths algorithms. for things like closest point between 2 lines etc.

oh another good site or 2:-
http://www.euclideanspace.com/maths/...ourD/index.htm
http://local.wasp.uwa.edu.au/~pbourk...try/planeline/
I put the source of the algorithms in my comments.
although the plane <-> plane <-> plane intersect doesnt seem to have it listed thats a doozy of a function

Last edited by meow; 25-05-2009 at 13:27..
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Tools meow is online now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27-05-2009, 04:19   #6 (permalink)
Name, Title, Location LippoW
Pompous atheist

Oulu
Finland
AvatarLippoW's Avatar
Mood
Posts1,363
Karma LippoW is an experienced TFer.
LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.LippoW is an experienced TFer.
Pu6,603.88
Four Leaf Clover Four Leaf Clover Four Leaf Clover Four Leaf Clover Big Beer Big Beer Big Beer Big Beer
Default

x to the power of x = y

For a qbasic source code (switch x with y in this case). Google, I love it.
ToolsLippoW is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27-05-2009, 10:10   #7 (permalink)
Name, Title, Location Sash
BiteMe

South Yorkshire
United Kingdom
AvatarSash's Avatar
Mood
Posts5,790
Karma Sash is one of the elite.Sash is one of the elite.Sash is one of the elite.Sash is one of the elite.
Sash is one of the elite.Sash is one of the elite.Sash is one of the elite.Sash is one of the elite.
Pu2,905.55
Critters
Blog
Blog Entries: 1
Awards
TF Top Poster - Silver 
Total Awards: 1
Heart Champagne Pizza Iced Lolly Umbrella Tiger Cat 1 Cat 3
Default

ohhh I think you're lovely Meow but you don't half make me feel thick! lol
Sash's Sig:
Tools Sash is online now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27-05-2009, 13:57   #8 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,205
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,762.87
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default

sorry lol
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Tools meow is online now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27-05-2009, 14:25   #9 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,205
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,762.87
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default

Quote:
Originally Posted by LippoW View Post
x to the power of x = y

For a qbasic source code (switch x with y in this case). Google, I love it.
thanks, sorry wont let me karma you :s

I had a look and it took me a while to get my head around, but the iteration loop is for 3000 lol.

actually after some time looking it seems this is exactly the same as I did it initially:-
its taking the nth root of y and averaging the result with n for the next guess, as y seems to always be inbetween these two values. ie if n is too low the result is going to be to high.

whereas I used Pow(x,1/n), this example uses logs to achieve the same thing.
however the convergence can be quite slow,

(if n2 is the n1th root of x)
using n=n+log(n1^n1/n2^n2) is actually very fast :- jumping almost directly to the value even on the first pass of the loop.

I just stumbled across this by accident when trying any different function I could think of that was a closer fit of the 2 results to the actual error. but I'm puzzled as to why it is so uncannily close.
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Tools meow is online now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27-05-2009, 16:59   #10 (permalink)
Name, Title, Location Seth
AARRGGHH!

Sheffield, S. Yorks
England
AvatarSeth's Avatar
Mood
Posts5,509
Karma Seth is advanced.Seth is advanced.Seth is advanced.
Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.Seth is advanced.
Pu4,655.15
Awards
TF Top Poster Bronze TF Top Poster - Silver 
Total Awards: 2
TV Sunderland AFC
Default

...and that's the reason I dislike pure mathematics.
Seth's Sig:
Seth

Mir 3: Auraya - Lv 15 - Taoist

EVE:
ToolsSeth is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27-05-2009, 18:38   #11 (permalink)
Name, Title, Location Ixpah
Full Member

Nottingham, UK
England
AvatarIxpah's Avatar
Mood
Posts335
Karma Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.
Pu8,096.80
Default

Using the simple approximation one I get:-
x=4,y=2.20681623447875
x=256,y=4.15330265177627
x=3125,y=5.13365919367039
x=46656,y=6.11794457569541

using the more complex iterative one, you can get the correct answer in 6 iterations for the above examples.

If you range of values for x is limited, e.g. its always an integer, and precision doesn't matter much maybe a quick look up table would be a quicker solution? If its time critical code.

Code:
		static void Main(string[] args)
		{
			TestW(4);
			TestW(256);
			TestW(3125);
			TestW(46656);
		}
		static void TestW(double In)
		{
			double Out;

			Out = Math.Log(In) / desy_lambert_W(Math.Log(In));

			Console.WriteLine("x=" + In.ToString() + ",y=" + Out.ToString());
		}

		static double LambertW(double x)
		{
			double w = 0.0;
			double we;
			double w1e;
			double prec = 1E-14;
			for(int i=1; i<100; i++)
			{
				we = w * Math.Pow(Math.E, w);
				w1e = (w + 1) * Math.Pow(Math.E, w);

				if (prec > Math.Abs((x - we) / w1e))
					return w;

				w -= (we - x) / (w1e - ((w + 2) * (we - x)) / (2 * w + 2));
			}
			return w;
		}
		static double desy_lambert_W(double x)
		{
			double lx1;
			if (x <= 500.0)
			{
				lx1 = Math.Log(x + 1.0);
				return 0.665 * (1 + 0.0195 * lx1) * lx1 + 0.04;
			}
			return Math.Log(x - 4.0) - (1.0 - 1.0 / Math.Log(x)) * Math.Log(Math.Log(x));
		}
Ixpah's Sig:Check out my forums @ zints.co.uk or My Blog
ToolsIxpah is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links

Old 27-05-2009, 21:05   #12 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,205
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,762.87
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default

thanks, well my input is integer based, so although the result has to be floating point, if y^y is within 0.5 then thats as close as one could expect anyway. Ive yet to see my loop reach above 6.


I could use something simpler, its simply used for calculating the base number of the vertex space partition tree. ie the classical trees are either binary or octal, a binary space partition tree has a base of 2 and an octal tree has a base of , well 8.

they differ in how fast they are to build and search, so my tree should be somewhere between the two.
however my tree is rather radical different to either anyway.

ie for x entries in the table, there will be y levels each node containing y items.
its all about trading off search time and build time so that its best overall.

getting an optimum value cuts down both the time to build it and search it.
well thats what I'm hoping, it does seem to so far, the profiler says its
spending less than 1% time here now which is ok.

the cache gets used and rebuilt a lot. theres upto 300k vertexes
each vertex has to be compared with every other vertex,
this alone would take ages if it didn't filter only the ones close by.

not only that but the vertexes are built up from thousands of model objects, the cache gets rebuilt every time a model object is added, so it gets both built a lot and used a lot.

I would like to build a dynamic partition tree, but thats really too difficult for me,
unless anyone fancies a go at it ?
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Tools meow is online now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
iteration, newton, raphson, xyy

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Roma Victor update 2008 Sash Roma Victor 0 10-01-2008 16:23
Freebie Sites Detomah Shopping Offers 0 01-11-2007 16:07
Top 100 Foods to Improve Your Productivity Cintaria Health, Lifestyle, Hobbies and Sport 3 21-08-2007 08:53
Dyslexia Detomah Health, Lifestyle, Hobbies and Sport 0 05-11-2006 17:50
how do i find out... meris General Computer Discussion 12 19-06-2003 20:15

 
 
Archive - RSS Feeds - About Us - Privacy - Terms of Use - Site Map - Advertising - Link To TF - Contact Us - Top
Content Relevant URLs by vBSEO 3.2.0 RC5 Copyright ©2003 - 2000, Total Format. Forums powered by vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Limited.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393