(*********************************************************************** This file was generated automatically by the Mathematica front end. It contains Initialization cells from a Notebook file, which typically will have the same name as this file except ending in ".nb" instead of ".m". This file is intended to be loaded into the Mathematica kernel using the package loading commands Get or Needs. Doing so is equivalent to using the Evaluate Initialiation Cells menu command in the front end. DO NOT EDIT THIS FILE. This entire file is regenerated automatically each time the parent Notebook file is saved in the Mathematica front end. Any changes you make to this file will be overwritten. ***********************************************************************) (* Worldwide Mathematica Conference - Chicago 1998 *) (* file FitData.m: creates data for least-squares polynomial fitting *) (* Copyright \[Copyright] 1998 by Murray Eisenberg *) Begin["special`temp`"] (* encapsulate whole file *) (* Check for needed globals *) (* checking myID and myName *) datapts`check`checking::noID = "\nYou forgot to define myID!"; datapts`check`checking::badID = "\nmyID must be a string, enclosed in quotes, consisting "<> "of the digits of your student ID number."; datapts`check`checking::noName = "\nYou forgot to define "<> "myName!"; datapts`check`checking::badName = "\nmyName must be a string, enclosed in quotes, consisting "<> "of at least three letters of your (first) name."; datapts`check`checkingNoID = If[Names["myID"] === {}, True, False]; datapts`check`checkingNoName = If[Names["myName"] === {}, True, False]; datapts`check`checkingOK = If[datapts`check`checkingNoID, Message[datapts`check`checking::noID]; False, If[!StringQ@ToExpression@"myID", Message[datapts`check`checking::badID]; False, If[(!Apply[And, Map[MemberQ[Characters@"0123456789", #]&, Characters@ToExpression@"myID"]]) || (0 == StringLength@ToExpression@"myID"), Message[datapts`check`checking::badID]; False, If[datapts`check`checkingNoName, Message[datapts`check`checking::noName]; False, If[!StringQ@ToExpression@"myName", Message[datapts`check`checking::badName]; False, If[(!Apply[And, Map[MemberQ[Characters@"ABCDEFGHIJKLMNOPQRSTUVWXYZ", #]&, Characters@ToUpperCase@ToExpression@"myName"]]) || (3 > StringLength@ToExpression@"myName"), Message[datapts`check`checking::badName]; False, True ]]]]]]; If[datapts`check`checkingOK, BeginPackage["datapts`"] ] If[datapts`check`checkingOK, Begin["`Private`"] ] (* SETUP AND TEST ... *) If[datapts`check`checkingOK, (* PREPARE TEST DATA *) (* Functions used to generate test data *) SeedRandom[Floor[0.123456 * ToExpression@ToExpression@"Global`myID"]]; Options[roll] = {dice \[Rule] 0}; roll[n_Integer?Positive, opts___?OptionQ] := Module[{k}, k = dice/.{opts} /. Options[roll]; If[k == 0, Random[Integer, {1, n}], Table[Random[Integer, {1, n}], {k}] ] ]; roll[m_Integer, n_Integer, opts___?OptionQ] := Module[{k}, k = dice/.{opts} /. Options[roll]; If[k == 0, Random[Integer, {m, n}], Table[Random[Integer, {m, n}],{k}] ] ]; (* must split off cst term to avoid Indeterminate 0^0 *) polyval[c_, x_] := c\[LeftDoubleBracket]1\[RightDoubleBracket] + Sum[c\[LeftDoubleBracket]j+1\[RightDoubleBracket] x^j, {j, 1, Length[c] - 1}]; makexymat := Module[{id, n, c, m, fuzz, x, y}, id = ToExpression@(ToExpression@"Global`myID"); n = 3 + Mod[id, 7]; c = 0.1 roll[-14, 25, dice \[Rule] n + 1]; m = Length@c; c\[LeftDoubleBracket]m\[RightDoubleBracket] = 0.1 roll[5]; fuzz = 0.0001 roll[-99, 200, dice \[Rule] roll[31, 60]]; x = 0.01 roll[-299, 300, dice \[Rule] Length[fuzz]]; x = Sort[x]; y = (polyval[c, #]&) /@ x; y = y + fuzz; Transpose[{x, y}] ]; (* CREATE DATA *) (* Form problem data and instructions *) stateProblem[name_] := (xy = makexymat; dataSave[name<>"data", "The list of xy data pairs", "xy"] ); (* GENERAL PROBLEM-POSING FUNCTIONS *) dataSave[varname_String, what_String, dataname_String] := (ToExpression[StringJoin[Sequence@@{"Global`"<>varname, "=", dataname}]]; {(what<>" is stored in variable "),varname}); startline[id_String] := "Data for ID #"<>id<>" prepared "<>tstamp[Date[]]<> " ...\n"; tstamp[when_] := Module[{t, year, month, day, hour, minute}, t = If[Length[when] == 0, Date[], when]; t\[LeftDoubleBracket]1\[RightDoubleBracket] = Mod[t\[LeftDoubleBracket]1\[RightDoubleBracket], 100]; {year, day, hour, minute} = Map[ToString, t\[LeftDoubleBracket]{1, 3, 4, 5}\[RightDoubleBracket]]; minute = StringTake["0"<>minute, -2]; month = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}\[LeftDoubleBracket]t\[LeftDoubleBracket]2\[RightDoubleBracket]\[RightDoubleBracket]; day<>" "<>month<>" "<>year<>", "<>hour<>":"<>minute]; firstStringPosition[t_String, ch_String] := StringLength[t] + 1 /; StringPosition[t, ch] === {}; firstStringPosition[t_String, ch_String] := First@Flatten@StringPosition[t, ch]; setup[id_String, name_String] := Module[{nameStub, aboutProblem}, nameStub = ToUpperCase@StringTake[name, 3]; aboutProblem = stateProblem[nameStub]; CellPrint[Cell[TextData[ { StyleBox[startline[id], FontWeight->"Bold"], aboutProblem[[1]], StyleBox[aboutProblem[[2]], FontFamily->"Courier"] }], "Text", CellFrame->True, Background->GrayLevel[0.849989]] ] ]; (* Execute it! *) setup[ToExpression@"Global`myID", ToExpression@"Global`myName"]; ] (* endIf -- end setup *) datapts`check`checkingOK = True; If[datapts`check`checkingOK, End[] (* end Private *) ] If[datapts`check`checkingOK, EndPackage[] ] (* CLEAN UP *) (* clean up in case myID or myName was not defined *) If[datapts`check`checkingNoID, Remove[myID] ]; If[datapts`check`checkingNoName, Remove[myName] ] (* Don't leave package context in $ContextPath or $Packages! *) If[datapts`check`checkingOK, $ContextPath= Drop[$ContextPath, 1] ] Delete[$Packages, Position[$Packages, "datapts`"]] Remove["datapts`check`*"] (* clean up `check` objects *) Off[Remove::rmnsm]; Remove["special`temp`*"]; (* remove all locals in this file *) On[Remove::rmnsm] End[]; (* end special`temp` *) (* end of file *)