Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline johnnyontheweb  
#1 Posted : 20 September 2021 19:35:14(UTC)
johnnyontheweb


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

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline uni  
#2 Posted : 20 September 2021 19:40:30(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,493
Man
Russian Federation

Was thanked: 1274 time(s) in 745 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
Viacheslav N. Mezentsev
Offline johnnyontheweb  
#3 Posted : 20 September 2021 20:03:28(UTC)
johnnyontheweb


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"Wink and inside plugin code I get "C\003A\\test\002E\txt"
002E is "." in UTF8, but there's also escape chars.
Offline uni  
#4 Posted : 20 September 2021 20:06:49(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,493
Man
Russian Federation

Was thanked: 1274 time(s) in 745 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
Viacheslav N. Mezentsev
Offline johnnyontheweb  
#5 Posted : 20 September 2021 21:50:43(UTC)
johnnyontheweb


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?
Offline uni  
#6 Posted : 20 September 2021 22:33:08(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,493
Man
Russian Federation

Was thanked: 1274 time(s) in 745 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
Viacheslav N. Mezentsev
Offline johnnyontheweb  
#7 Posted : 21 September 2021 17:25:19(UTC)
johnnyontheweb


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

Offline uni  
#8 Posted : 21 September 2021 21:06:30(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,493
Man
Russian Federation

Was thanked: 1274 time(s) in 745 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
Viacheslav N. Mezentsev
Offline johnnyontheweb  
#9 Posted : 21 September 2021 21:49:52(UTC)
johnnyontheweb


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.
Offline Jean Giraud  
#10 Posted : 21 September 2021 23:30:37(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Originally Posted by: johnnyontheweb Go to Quoted Post
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 7 time(s).

Offline overlord  
#11 Posted : 21 September 2021 23:37:52(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,125
Turkey

Was thanked: 506 time(s) in 337 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Associate unit compatible to functional operand
as exemplified ... integration is m² km² ...

Page12 Unit_Bolean.sm (14kb) downloaded 7 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.
Offline uni  
#12 Posted : 22 September 2021 00:08:23(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,493
Man
Russian Federation

Was thanked: 1274 time(s) in 745 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
Viacheslav N. Mezentsev
thanks 1 user thanked uni for this useful post.
on 22/09/2021(UTC)
Offline johnnyontheweb  
#13 Posted : 12 October 2021 10:38:19(UTC)
johnnyontheweb


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

Offline johnnyontheweb  
#14 Posted : 13 October 2021 13:26:17(UTC)
johnnyontheweb


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))
Users browsing this topic
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.