[system] / trunk / pg / lib / Value / Formula.pm Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# Diff of /trunk/pg/lib/Value/Formula.pm

Revision 2687 Revision 2688
308# Find adaptive parameters, if any 308# Find adaptive parameters, if any
309# 309#
311 my \$l = shift; my \$r = shift; 311 my \$l = shift; my \$r = shift;
312 my @params = @_; my \$d = scalar(@params); 312 my @params = @_; my \$d = scalar(@params);
313 return 0 if \$d == 0; 313 return 0 if \$d == 0; return 0 unless \$l->usesOneOf(@params);
314 \$l->Error("Adaptive parameters can only be used for real-valued functions") 314 \$l->Error("Adaptive parameters can only be used for real-valued functions")
315 unless \$l->{tree}->isRealNumber; 315 unless \$l->{tree}->isRealNumber;
316 # 316 #
317 # Get coefficient matrix of adaptive parameters 317 # Get coefficient matrix of adaptive parameters
318 # and value vector for linear system 318 # and value vector for linear system
336 (\$M,\$B) = \$M->normalize(\$B); 336 (\$M,\$B) = \$M->normalize(\$B);
337 \$M = \$M->decompose_LR; 337 \$M = \$M->decompose_LR;
338 if ((\$d,\$B,\$M) = \$M->solve_LR(\$B)) { 338 if ((\$d,\$B,\$M) = \$M->solve_LR(\$B)) {
339 if (\$d == 0) { 339 if (\$d == 0) {
340 # 340 #
341 # Get values and recompute the points using them 341 # Get parameter values and recompute the points using them
342 # 342 #
343 my @a; foreach my \$r (@{\$B->[0]}) {push @a, \$r->[0]} 343 my @a; my \$i = 0; my \$max = \$l->getFlag('max_adapt',1E8);
344 foreach my \$row (@{\$B->[0]}) {
345 if (abs(\$row->[0]) > \$max) {
346 \$l->Error("Constant of integration is too large: \$row->[0]")
347 if (\$params[\$i] eq 'C0');
348 \$l->Error("Adaptive constant is too large: \$params[\$i] = \$row->[0]");
349 }
350 push @a, \$row->[0]; \$i++;
351 }
344 \$l->{parameters} = [@a]; 352 \$l->{parameters} = [@a];
345 \$l->createPointValues; 353 \$l->createPointValues;
346 return 1; 354 return 1;
347 } 355 }
348 } 356 }
349 \$l->Error("Can't solve for adaptive parameters"); 357 \$l->Error("Can't solve for adaptive parameters");
358}
359
360sub usesOneOf {
361 my \$self = shift;
362 foreach my \$x (@_) {return 1 if \$self->{variables}{\$x}}
363 return 0;
350} 364}
351 365
352## 366##
353## debugging routine 367## debugging routine
354## 368##

Legend:
 Removed from v.2687 changed lines Added in v.2688