Skip to content

Commit

Permalink
Fix bug 4690
Browse files Browse the repository at this point in the history
  • Loading branch information
gajennings committed Apr 12, 2022
1 parent 948febf commit 11b01a9
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions OpenProblemLibrary/UBC/setTaylor/testingError.pg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## DBsection(Taylor series)
## Level(3)
## MO(1)
## Static(1)
## This problem is a good template for questions with Taylor Polynomials

DOCUMENT();
Expand All @@ -24,7 +25,7 @@ Context("Numeric");
#Number of decimals to use in the approximation
$dec = 3;

$smallDec = 10**{-$dec};
$smallDec = 10**(-$dec)/2;
Context()->flags->set(
tolerance=>$smallDec,
tolType=>"absolute"
Expand All @@ -43,23 +44,23 @@ $x = 10;
$f[0] = Formula("(1+x)^(1/2)");

# The zero degree approximation
$tn[0] = $f[0]->eval(x=>"$a");
$tn[0] = Real($f[0]->eval(x=>"$a"));

# code to compute the nth degree approximation
$nfact = 1;
for my $i (1..$n)
{
$f[$i] = $f[$i-1]->D;
$fa = $f[$i]->eval(x=>"$a");
$tn[$i] = $tn[$i-1]+$fa*($x-$a)**($i)/$nfact;
$f[$i] = $f[$i-1]->D('x');
$fa = $f[$i]->eval(x=>$a);
$tn[$i] = Formula($tn[$i-1]+$fa*($x-$a)**($i)/$nfact);
$nfact = $nfact*($i+1);
}

#decreasing the number of decimal places
for my $i (1..$n)
{
$sTn[$i] = sprintf("%0.4f",$tn[$i]);
}
##decreasing the number of decimal places
#for my $i (1..$n)
#{
#$sTn[$i] = sprintf("%0.4f",$tn[$i]);
#}

Context()->texStrings;
BEGIN_TEXT
Expand All @@ -81,36 +82,44 @@ Context()->normalStrings;

Context()->texStrings;
BEGIN_TEXT
$BR $BBOLD Use $dec decimal places in your answer $EBOLD
$BR $BBOLD Your answer must be accurate to at least $dec decimal places.$EBOLD

$PAR
END_TEXT
Context()->normalStrings;

for $i (1..$n)
{
ANS(Compute("$sTn[$i]")->cmp() );
}
#for $i (1..$n)
#{
#ANS(Compute("$sTn[$i]")->cmp() );
#}

#for $i (1..$n) {
#ANS(Compute($tn[$i]->eval(x=>$x))->cmp());
#}

ANS(Compute($tn[1])->cmp());
ANS(Compute($tn[2])->cmp());
ANS(Compute($tn[3])->cmp());


# You will have to change most of the solution to fit the question
Context()->texStrings;
BEGIN_SOLUTION
$PAR SOLUTION $PAR
In general the \(n^{th}\) degree approximation of \(f($x)\) about \(x=$a\) is given by:
$BR \(T_n = f($a) + f'($a)($x-a) + \ldots + \frac{f^n($x)}{n!}($x-$a)^n\)
In general the \(n^{th}\) degree approximation of \(f(x)\) about \(x=$a\) is given by:
$BR \(T_n = f($a) + f'($a)(x-$a) + \ldots + \frac{1}{n!}{f^{(n)}($a)}($x-$a)^n\)

$PAR
\(f'(x) = \frac{1}{x\sqrt{1+x}}\),
$BR \(f''(x) = -\frac{1}{4(1+x)^{\frac{3}{2}}}\),
$BR \(f'''(x) = \frac{3}{8(1+x)^{\frac{5}{2}}}\).
Here,
\(f'(x) = \frac{1}{2}(x+1)^{-1/2}\),
$BR \(f''(x) = -\frac{1}{4}(x+1)^{-3/2}\),
$BR \(f'''(x) = \frac{3}{8}(x+1)^{-5/2}\).

$PAR
Therefore,
$BR \(T_1 = $sTn[1]\),
$PAR \(T_2 = $sTn[2]\),
$PAR \(T_3 = $sTn[3]\).
$BR \(T_1($x) \approx $tn[1]\),
$PAR \(T_2($x) \approx $tn[2]\),
$PAR \(T_3($x) \approx $tn[3]\).

END_SOLUTION
Context()->normalStrings;
Expand Down

0 comments on commit 11b01a9

Please sign in to comment.