I want to convert this Cos up -1 to Tcl - tcl

can anyone tell me how can I convert this cos-1 to TCL, due to in TCL
just work with normal cos, not like this cos-1, also it calls "The inverse cosine".

If you want the reverse cosine in degree, you could use this:
expr {acos($x)*180/acos(-1)}
acos(-1) is pi.

Tcl has always called the inverse cosine function acos; it's part of expressions:
% expr { acos(0.123) }
1.4474840516030245
Result is in radians, of course.

Related

Dirac function in TCL

I am using a structural software that uses TCL as a programming language.
Does anyone how to define dirac functions in TCL? From the examples I got hold of, 4 arguments are required. What do they correspond to?
This is how the function is defined in my examples:
#
diract(tint,0*dt,dt,dt)
#
Thank you in advance
PS: I am struggling to find some good documentation. Any recommendation ?
Given that we have a finite step size (because we're using IEEE double precision floating point, the Dirac delta function is just this:
proc tcl::mathfunc::delta {x} {
expr {$x == 0.0 ? 4.49423283715579e+307 : 0.0}
}
That gives a delta function with a very large impulse at the origin (where the width of the impulse is determined by the size of the smallest non-denormalized number; that number is one of the largest that can be represented by floating point without using infinity).
That's not all that useful, as it's using floating point equality in its definition (and that rightfully has some major caveats attached to it). More usefully is fact that the integral of it is such that it is 0 when x is less than 0 and 1 when x is more than 0.
I'm not sure what the arguments you're looking to provide mean, especially given that 0*dt one of them.

Specify a general scalar function within a vector operation in Mathematica?

I am trying to take the derivative of a function that includes a scalar function of a vector and the vector itself. A simpler example of this is:
D[ A[b[t]]*b[t]/(b[t].b[t]), t]
where b[t] is a 3-vector and A[b[t]] is a scalar function. I get nonsense back out, since Mathematica isn't properly defining A[b[t]] to be a scalar.
I've tried using $Assumptions = {(b[t]) \[Element] Vectors[3, Reals], (M[b[t]] | t) \[Element] Reals} and this doesn't seem to help.
Any tips?
Edit to add more detail:
In that example case, I should get:
A/(b[t].b[t]) * (2(b[t].b'[t])b[t]/(b[t].b[t])^2 - b'[t])
- D[A,b]*1/(b[t].b[t])^(3/2) * (b[t].b'[t])b[t]
Where ' denotes a derivative with respect to t.
Mathematica gives everything correctly except the last term. The last term is instead:
-((b[t] b'[t] M'[b[t]])/b[t].b[t])

Can I define a maxima function f(x) which assigns to the argument x

Sorry for the basic question, but it's quite hard to find too much discussion on Maxima specifics.
I'm trying to learn some Maxima and wanted to use something like
x:2
x+=2
which as far as I can tell doesn't exist in Maxima. Then I discovered that I can define my own operators as infix operators, so I tried doing
infix("+=");
"+=" (a,b):= a:(a+b);
However this doesn't work, as if I first set x:1 then try calling x+=2, the function returns 3, but if I check the value of x I see it hasn't changed.
Is there a way to achieve what I was trying to do in Maxima? Could anyone explain why the definition I gave fails?
Thanks!
The problem with your implementation is that there is too much and too little evaluation -- the += function doesn't see the symbol x so it doesn't know to what variable to assign the result, and the left-hand side of an assignment isn't evaluated, so += thinks it is assigning to a, not x.
Here's one way to get the right amount of evaluation. ::= defines a macro, which is just a function which quotes its arguments, and for which the return value is evaluated again. buildq is a substitution function which quotes the expression into which you are substituting. So the combination of ::= and buildq here is to construct the x: x + 2 expression and then evaluate it.
(%i1) infix ("+=") $
(%i2) "+="(a, b) ::= buildq ([a, b], a: a + b) $
(%i3) x: 100 $
(%i4) macroexpand (x += 1);
(%o4) x : x + 1
(%i5) x += 1;
(%o5) 101
(%i6) x;
(%o6) 101
(%i7) x += 1;
(%o7) 102
(%i8) x;
(%o8) 102
So it is certainly possible to do so, if you want to do that. But may I suggest maybe you don't need it? Modifying a variable makes it harder to keep track, mentally, what is going on. A programming policy such as one-time assignment can make it easier for the programmer to understand the program. This is part of a general approach called functional programming; perhaps you can take a look at that. Maxima has various features which make it possible to use functional programming, although you are not required to use them.

Is it possible to write (display) exponential equations in scilab?

I've been trying to display in my console an exponential equation like the following one:
y(t) = a*e^t + b*e^t + c*e^t
I would write it as a string, however the coefficients a,b and c, are numbers in a vector V = [a b c]. So I was trying to concatenate the numbers with strings "e^t", but I failed to do it. I know scilab displays polynomial equations, but I don't know it is possible to display exponential one. Anyone can help?
Usually this kind of thing is done with mprintf command, which places given numerical arguments into a string with formatting instructions.
V = [3 5 -7]
mprintf("y(t) = %f*e^t + %f*e^t + %f*e^t", V)
The output is
y(t) = 3.000000*e^t + 5.000000*e^t + -7.000000*e^t
which isn't ideal, and can be improved in some ways by tweaking the formatters, but is readable regardless.
Notice we don't have to list every entry V(1), V(2), ... individually; the vector V gets "unpacked" automatically.
If you wanted to have 2D output like what we get for polynomials,
then no, this kind of thing is what Scilab does for polynomials and rational functions only, not for general expressions.
There is also prettyprint but its output is LaTeX syntax, like $1+s+s^{2}-s^{123}$. It works for a few things: polynomials, rational functions, matrices... but again, Scilab is not meant for symbolic manipulations, and does not really support symbolic expressions.

sin equation in python keeps returning the wrong answer

I think I have a buggy version of python, because I am getting the wrong result. If you type this: sin(degrees(39))*41/28 directly into google, you will get the value 0.92150485832. This is the correct value for the given equation.
When I try to execute this in python however, I get the value -1.11258224646.
The code I used:
number= float(sin(degrees(39))*41/28)
print number
I also tried the following code (removed degrees surrounding the 39), which returns the value 1.41127181563.
number= float(sin(39)*41/28)
print number
Just for the kicks, I also tried the code like this:
number= float(sin(radians(39))*41/28)
print number
This code returned the answer 0.921504858323, which would be the correct answer for the first equation
That shouldn't be possible as 39 in radians is 0.680678408. And using that number in the equation: (sin(0.680678408)*41)/28 we get 0.017395421, not 0.921504858323.
Can someone please explain what's going on here. I'm lost here.
The explanation is in difference of interpretation of words "degrees" and "radians" between google and python.
In python these 2 are functions for converting from one unit to another:
math.degrees(x) - Convert angle x from radians to degrees.
math.radians(x) - Convert angle x from degrees to radians.
To evaluate "float(sin(radians(39))*41/28)" statement python converts 39 degrees angle into radians (0.680678) then computing sin(x) which returns the sine of x radians, so we will get sin(39 degree)*41/28.
Google uses 2 words for clarification of unit and not for conversion.
to evaluate "sin(degrees(39))*41/28" google understands it as "sin(39 degree)*41/28", so it is not converting units between radians and degrees. It is just calculation sine of 39 degree.
Use this
>> math.sin(math.radians(39))*41/28
0.9215048583229761