I fully agree with Mathcad that 'this variable is undefined'. You ask why?
In the first line, defining k.g, you use a variable t that is not defined at that moment. It is defined several lines down.
Note that in this same definition P(t) is also undefined. But Mathcad only reports a single error per equation.
In the second line, defining k.d, you use P(t) again, and it still is not defined (yet). That only happens in the following line.
You should learn a few things very well if you want to use Mathcad:
Use := to define a variable or function. The symbol to be defined is to the left of :=, the definition goes to the right of it.
Use = to evaluate a variable or function (get it's value, have it displayed). The symbol to be evaluated must be to the left of the =, the result will be shown to the right of it (if it can be calculated).
Use = to compare the value of a variable or function with another value (of a constant, variable or function).
And finally: Mathcad reads sheets from left to right and top to bottom. If you want to use a symbol (variable or function) it MUST be defined beforehand; that is; above and/or to the left of where you use it.