Rank: Member Groups: Registered
Joined: 15/10/2013(UTC) Posts: 19
Was thanked: 3 time(s) in 1 post(s)
|
Hello all, I'm new to SMath Studio, and I'm developing a plugin in VB.NET. I need to define a constant given from my code (for example, I want to type in "const=" and get an hardcoded value). I saw that TermType can be Operand, Operator, Function or Bracket. I defined my constant as a function, and in this way I always have to type const(1) to get the value (i.e. I must use a dummy argument, which is not needed).
Do you have any hint on that? Can I defined a constant in a plugin?
thanks in advance
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 10/11/2010(UTC) Posts: 1,639 Was thanked: 1400 time(s) in 817 post(s)
|
As I know it is not possible. All plugin stuff (if they are not regions) registered as functions. But I've never tried registering an operand instead of a function. I tried. You can register the operand, but an error occurs when you try to calculate it numerically. Edited by user 20 September 2021 20:03:57(UTC)
| Reason: Not specified |
Russia ☭ forever (git.io/vOZo0) Viacheslav N. Mezentsev |
|
|
|
Rank: Member Groups: Registered
Joined: 15/10/2013(UTC) Posts: 19
Was thanked: 3 time(s) in 1 post(s)
|
Thans for replying It seems I cannot also use system paths as a function arguments; I suspect there's something about encoding: I have myfunc("C:\test.txt" and inside plugin code I get "C\003A\\test\002E\txt" 002E is "." in UTF8, but there's also escape chars.
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 10/11/2010(UTC) Posts: 1,639 Was thanked: 1400 time(s) in 817 post(s)
|
You must use TermsConverter.DecodeText() and TermsConverter.EncodeText() for this. Examples can be found in the repository. Edited by user 20 September 2021 20:08:38(UTC)
| Reason: Not specified |
Russia ☭ forever (git.io/vOZo0) Viacheslav N. Mezentsev |
|
|
|
Rank: Member Groups: Registered
Joined: 15/10/2013(UTC) Posts: 19
Was thanked: 3 time(s) in 1 post(s)
|
Thanks a lot. Final question: can a function return a boolean?
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 10/11/2010(UTC) Posts: 1,639 Was thanked: 1400 time(s) in 817 post(s)
|
The program supports operations with numbers presented in various forms (natural, integer, rational, complex). There is no such type as boolean numbers. There are boolean operations defined on the above types. Therefore, there are numbers and operations on them, strings and operations on them, matrices and operations on them. The type of a variable is determined by its value. In symbolic form, you can return any expression allowed by the program syntax.
Therefore, if you need to return a boolean value from a plugin, then it needs to be converted to a value supported in API (see TNumber constructors). Usually, true - 1, false - 0. |
Russia ☭ forever (git.io/vOZo0) Viacheslav N. Mezentsev |
|
|
|
Rank: Member Groups: Registered
Joined: 15/10/2013(UTC) Posts: 19
Was thanked: 3 time(s) in 1 post(s)
|
Thanks, hence it would be easier to put result in an expression with a boolean operator and then return result. I'm just wondering how to return vectors, I cannot understand from Core Documentation how to return a vector as a result. I suppose one can use some thing like: result = New Entry(New Numeric.TMatrix(... ? )) and using 1 column only. can you help on this? thanks in advance EDIT: I did it like this - now the question is: is there a shorter way? Code: Dim val() As Double = {1,2,3,4,5,6}
Dim m(5, 0) As Numeric.TNumber
For i = 0 To 5
m(i, 0) = New Numeric.TNumber(val(i))
Next
Dim mout As New Numeric.TMatrix(m)
result = Entry.Create(mout.ToTerms)
Edited by user 21 September 2021 17:36:04(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 10/11/2010(UTC) Posts: 1,639 Was thanked: 1400 time(s) in 817 post(s)
|
You can find examples in repository. Try to search in *.cs files using keyword TMatrix. And then convert to the equivalent on vb.net. |
Russia ☭ forever (git.io/vOZo0) Viacheslav N. Mezentsev |
|
|
|
Rank: Member Groups: Registered
Joined: 15/10/2013(UTC) Posts: 19
Was thanked: 3 time(s) in 1 post(s)
|
I already saw that page, thanks. Don't know if it's for vb instead of c#, but I cannot have "result = solution" since this conversion is not permitted. Now I'm looking how to associate units (eg. N, m or MPa, etc.) for result - I didn't find any code sample for this (I thought this https://smath.info:8443/!/#public/view/head/plugins/CustomFunctions/SMathFunctions/Units/UoM.cs was ok, but I cannot understand how units are associated to result). In my case, units are not inherited from function arguments.
|
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 983 time(s) in 811 post(s)
|
Originally Posted by: johnnyontheweb I cannot understand how units are associated to result Associate unit compatible to functional operand as exemplified ... integration is m² km² ... Page12 Unit_Bolean.sm (14kb) downloaded 11 time(s).
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/07/2013(UTC) Posts: 1,191 Was thanked: 544 time(s) in 366 post(s)
|
Originally Posted by: Jean Giraud Associate unit compatible to functional operand as exemplified ... integration is m² km² ... Page12 Unit_Bolean.sm (14kb) downloaded 11 time(s). The questions are about source code of a plugin. Not about how to write boolean expressions in SMath. This post is not related with topic. If you don't get what is asked, don't answer it.
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 10/11/2010(UTC) Posts: 1,639 Was thanked: 1400 time(s) in 817 post(s)
|
For example you can add units using TDouble. To determine the unit, you need to add an apostrophe in front of the text. For TryEvaluateExpression() you can use other methods (classes). Code:Public Class Plugin
Implements IPluginMathNumericEvaluation
Private _terms As TermInfo()
Private _description As Dictionary(Of String, String) = New Dictionary(Of String, String) From {
{"ENG", "test function."},
{"RUS", "функция тестирования."}
}
Public Function GetTermsHandled(sessionProfile As SessionProfile) As TermInfo() Implements IPluginHandleEvaluation.GetTermsHandled
Return _terms
End Function
Public Sub Initialize() Implements IPlugin.Initialize
_terms = {New TermInfo("test", TermType.[Function], _description("ENG"), FunctionSections.Unknown, True) }
End Sub
Public Function NumericEvaluation(value As Term, args As TNumber(), ByRef result As TNumber) As Boolean Implements IPluginMathNumericEvaluation.NumericEvaluation
result = args(0) * ( new TDouble("'sec") )
Return True
End Function
Public Sub Dispose() Implements IDisposable.Dispose
End Sub
End Class
|
Russia ☭ forever (git.io/vOZo0) Viacheslav N. Mezentsev |
1 user thanked uni for this useful post.
|
|
|
Rank: Member Groups: Registered
Joined: 15/10/2013(UTC) Posts: 19
Was thanked: 3 time(s) in 1 post(s)
|
Hello, I looked in the code by I cannot find something similar to what I'm trying to do with my plugin. A power of a length unit has to be returned as measure, but this is not working: New TNumber(area * New TDouble("'m^2" ) ) What am I missing? It seems that "^" operand is considered in a different way when typed in SMath Studio and when coming from a plugin. Edited by user 12 October 2021 10:39:50(UTC)
| Reason: removed smiley
|
|
|
|
Rank: Member Groups: Registered
Joined: 15/10/2013(UTC) Posts: 19
Was thanked: 3 time(s) in 1 post(s)
|
I found an alternative, please tell if there's something shorter than this:
New TNumber(area * DirectCast(New TDouble("'m" ).Pow(New TDouble(2) ), TDouble))
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.