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 TheWizEd  
#1 Posted : 18 March 2011 16:45:54(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
I started getting ambitious and was programming the financial functions in a plugin when I got stumped. How do you program the equation below? The problem is the j value is an index within the sum that identifies which element of the matrix to process at each step. Its a variable of the sum function. The plugin example shown in the wiki uses constants. By that I mean the values are all set and constant when the function is called. For the sum function the j index of the pmt# matrix has to vary.

You can get an idea of how the plugin should be programmed by looking at the SMath sm file using a text editor. But in the sm file j has been typed, is visible on the screen and is in the "Store". For the sum function to work properly in a plugin a new variable has to be created in the plugin program and placed in Store and fed to the sum function. Haven't been able to figure that out.



Any suggestions?
Ed

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

Offline bliengme  
#2 Posted : 18 March 2011 21:28:54(UTC)
bliengme

Rank: Newbie

Groups: Registered
Joined: 07/03/2011(UTC)
Posts: 3
Location: Canada

Using the same Cf as your example, I added a third arguement to fvc. So I have fvc(rate,pmt,n)
Not sure how you displayed your function !

I used fcv(rate, pmt,n):= SUM (from j=1 to n)pmt(sub j)* (1+rate)^(n-j+1)
My result from fvc(0.05,cf,n) was 13,814.98 agrees with an Excel worksheet I used for the same calculation
If there was a function to count size of a vector we could dispense with n
best wishes

fvc(rate,pmt,n)←sum((el(pmt,j)*((1+rate)^{n-j+1})),j,1,n)
How to get this to look like Smath?

Edited by user 18 March 2011 21:57:12(UTC)  | Reason: Not specified

Offline omorr  
#3 Posted : 18 March 2011 22:24:32(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello,
Paste a math region from SMath inside Math tags from BBcode Tags [ MATH ] [ /MATH ]. If you use point as decimal separator and comma as function argumets separator then just add "=eng" like "[ MATH=eng ]"
bliengme wrote:
How to get this to look like Smath?

fvc(rate,pmt,n)←sum((el(pmt,j)*((1+rate)^{n-j+1})),j,1,n)
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline TheWizEd  
#4 Posted : 18 March 2011 22:59:08(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
bliengme,

I'm using Windows so I'll describe how I do it. For Linux and others don't know.

First I Print Screen to capture the SMath image to the clip board.

Then in Paint I cut out the portion I want to display on this forum and save it to a png file.

Next I upload to the wiki. Click on the Wiki button on the SMath forum. I select File Management and then forum_attach. I created a directory for myself. You can create your own or just plop them into forum_attach. At the top of this page is a browse and upload button to pick a file from your computer and load it to the wiki.

Now when I'm composing a topic or reply I include the following in the body of my text. Type exactly as shown with the img, /img and %2f. I save this in a text file and simply cut and paste everytime I post a new picture. It easy once you get used to it.

Code:
[img]http://smath.info/wiki/GetFile.aspx?File=forum_attach%2fTheWizEd%2fsome_file_name.png[/img]


There's a tutorial "Adding images to an article" on the main wiki page. Good luck.

Radovan's method works for one equation at a time.

Edited by user 18 March 2011 23:11:04(UTC)  | Reason: Not specified

Ed
Offline TheWizEd  
#5 Posted : 19 March 2011 14:20:27(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
Well it might not be the most efficient but I figured out a solution. This example is different than the wiki code example in that the mathematics is done in code. The wiki example is done by stacking operations and passing back to SMath to do the math.

I had to pick apart the args passed to the VB code and what I discovered is that a number is not just a floating point number but a series of Terms. For example 1.1 is stored as 11,10,/. To get around this, cause I wouldn't know how many Terms a number may be composed of, was to use SMath Calculate function to pull the element out of the matrix. I create a small Term stack that requests the iRow-th element of the matrix and convert to floating point. Then do all the math in VB and return the results. Not sure if this is fool proof but it worked for test cases I performed.

Code:
        ElseIf root.Type = TermType.Function And root.Text = "fvc" And root.ChildCount = 2 Then
            Dim i As Integer
            Dim iRows As Integer
            Dim dRate As Double
            Dim dPmt As Double
            Dim dResult As Double
            Dim arg1 As Term() = Decision.Preprocessing(args(0), store)
            Dim arg2 As Term() = Decision.Preprocessing(args(1), store)
            dRate = SMath.Math.Numeric.Expression.Calculate(arg1, store).obj.ToDouble
            answer.Add(arg2(arg2.GetUpperBound(0) - 2))   ' Get number of rows
            iRows = SMath.Math.Numeric.Expression.Calculate(answer.ToArray, store).obj.ToDouble
            For i = 1 To iRows
                answer.Clear()
                answer.AddRange(arg2)
                answer.AddRange(Converter.ToTerms(i))
                answer.Add(New Term("el", TermType.Function, 2))
                dPmt = SMath.Math.Numeric.Expression.Calculate(answer.ToArray, store).obj.ToDouble
                dResult = dResult + (dPmt * (1 + dRate) ^ (iRows - i))
            Next
            answer.Clear()
            answer.AddRange(Converter.ToTerms(dResult))
            result = answer.ToArray()
            Return True


This technique will only work if there is only one value for each input and there are not units.

Edited by user 20 March 2011 15:34:14(UTC)  | Reason: Not specified

Ed
Offline TheWizEd  
#6 Posted : 20 March 2011 19:30:35(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
I've discovered a pecular side effect of using multiple value for variables. This effects both user functions and plugins.

The first example is the "combin" plugin example from the wiki, the second is a user function "combinf".

As shown below "a" has 2 values 5 and 6. You would expect 2 results, one for 5 and another for 6. But because "a" occurs twice in the equation you get 4 values. In the plugin "a" is pushed onto the stack twice so the equation is calculated twice for each occurance of "a".

Ed
Offline omorr  
#7 Posted : 22 March 2011 12:39:40(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello Ed,

I hope this would not be off the topic - I do not do programming and not able to make plugins.

The "Multiple value" operator makes me confused sometimes. I can not figure out what could be all of its uses and properties.

I thing that the two things are the main purpose of its using:
1 - Making multiple graphs
2 - using plus/minus, minus plus operators
7±8=sys(15,-1,2,1) 7±8±3=sys(18,2,12,-4,4,1)

On the other hand, its elements are vector elements.
a←sys(4,6,9,3,1)
el(a,1)=4 el(a,2)=6el(a,3)=9
We can, say, add or multiply "Multiple value" elements
a+a=sys(8,10,13,12,15,18,6,1)a*a=sys(16,24,36,54,81,5,1)
It seems that the operator will be performed on all the elements but the result will consist of only unique elements - the same elements will not be repeated (this is valid for the numerical result, not for the symbolical).
If you add some new vector elements:
el(a,6)←90el(a,8)←19
The result might be confusing because there is the difference between numeric and symbolic result
a=sys(4,6,9,0,90,19,6,1)a—sys(4,6,9,0,0,90,0,19,8,1)
Again, it seems that numerical result will not consist of repeated values in spite of the symbolic one. We can check this by:
el(a,8)=19
Moreover, if we assign the result to a variable - more surprises:
A←a+aB←a*a
A=sys(8,12,18,3,1)B=sys(16,36,81,3,1)
I guess this is due to the SMath symbolic behavior and processing of expression
a+a—2*sys(4,6,9,3,1)a*a—sys(4,6,9,3,1)^2
We can also mix it with a vectors or matrix as well
c←mat(22,25,33,3,1)
a+c=sys(mat(26,29,37,3,1),mat(28,31,39,3,1),mat(31,34,42,3,1),mat(22,25,33,3,1),mat(112,115,123,3,1),mat(41,44,52,3,1),6,1)a+c—mat(sys(4,6,9,0,0,90,0,19,8,1)+22,sys(4,6,9,0,0,90,0,19,8,1)+25,sys(4,6,9,0,0,90,0,19,8,1)+33,3,1)

Actually, the use of "Multiple values" still remained blurred to me.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline TheWizEd  
#8 Posted : 23 March 2011 04:23:13(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
Radovan,

I agree with you, "multiple value" is not something I normally deal with, but since SMath has that feature, I figured developing a function or plug has to plan for that possibility. It like a "what if" scenario. What if a is 5? What if a is 6? You simply build a variable with multiple values and solve both. For example the combin function should result in the results below but what happens is there are four solutions

combin(5,3)=10

combin(6,3)=20

a←sys(5,6,2,1)

combin(a,3) Gives you

5!/(3!*(5-3)!) = 10
6'/(3!*(6-3)!) = 20
5!/(3!*(6-3)!) = 3.333
6!/(3!*(5-3)!) = 60

It should have been if a = 5 or a = 6.
Ed
Offline maweilian  
#9 Posted : 06 April 2011 19:27:33(UTC)
maweilian


Rank: Advanced Member

Groups: Registered
Joined: 09/01/2010(UTC)
Posts: 102
Man
United States
Location: Oregon, USA

Was thanked: 5 time(s) in 5 post(s)
Ed,

I really want to continue learning myself about plugin development for Smath.

It would be great if you could edit existing pages and/or add new pages on the wiki under "Developer Guide" as you learn more about plugin development. Documentation on the Smath API is very sparse. I would like to see alot more on the wiki in this regard.

Would you be willing to post a link to your entire source code for the benefit of those who want to learn more about writing plugins? (A link to the source code could also be added to the wiki.)

I was the one would wrote the VB tutorial (and related video) on the wiki (using Andrey's C# example). I believe that the API has undergone some changes since that was written. I can post the Word document that was used to create the PDF tutorial if you would like to make any updates to it. Otherwise, I will try to update it as I pick up my learning process where I left off.
Will Massie
Mechanical Engineer
Oregon, USA
Offline TheWizEd  
#10 Posted : 07 April 2011 00:32:59(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
Will,

There are differences in programming between SMath 0.89 and 0.89 Beta. I've been toying with VB Express in developing plugin and found that the calling sequence of SMath functions in the core DLL libraries are different between the Stable and Beta version.

I was waiting until Andrey had completed his latest version before publishing my plugins. Maybe some of them become obsolete. Others will have to be reprogrammed.
Ed
Offline ing.sosa  
#11 Posted : 19 April 2011 16:09:09(UTC)
ing.sosa


Rank: Member

Groups: Registered
Joined: 29/08/2010(UTC)
Posts: 14
Location: Buenos Aires

Hi,

Im trying to follow the plugin tutorial with Visual Studio 2010, and found some errors:


Error 11 Value of type 'Boolean' cannot be converted to 'SMath.Manager.ArgumentInfo'. d:\documents\visual studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.vb 18 144 ClassLibrary1
Error 12 Omitted argument cannot match a ParamArray parameter. d:\documents\visual studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.vb 18 148 ClassLibrary1

Related to the line New TermInfo("dg", TermType.Function, 2, "(num, dig) - Devuelve num con dig dígitos significativos", FunctionSections.Unknown, True)

AND

Error 10 'Store' is a type and cannot be used as an expression. d:\documents\visual studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.vb 64 66 ClassLibrary1

Related to the line Dim arg2 As Term() = Decision.Preprocessing(args(1), Store)

Can anyone help me? I need to create functions to emulate simple and double precision for educational purposes. Thanks
Offline maweilian  
#12 Posted : 19 April 2011 18:10:04(UTC)
maweilian


Rank: Advanced Member

Groups: Registered
Joined: 09/01/2010(UTC)
Posts: 102
Man
United States
Location: Oregon, USA

Was thanked: 5 time(s) in 5 post(s)
Which version of Smath are you using? The tutorial, as it is written now, will not work for version 89.8 (beta). But it should work for version 0.89 (stable).

The first problem line should be:

New TermInfo("dg", TermType.Function, 2, "(num, dig) - Devuelve num con dig dígitos significativos", FunctionSection.Unknown, True)

(You addded an "s" to the end of "FunctionSection".)

If the program you are trying to write differs significantly from the tutorial, you probably should post a link to your entire source code in the forum. That way, we can test your code and help you better.
Will Massie
Mechanical Engineer
Oregon, USA
Offline ing.sosa  
#13 Posted : 19 April 2011 21:56:46(UTC)
ing.sosa


Rank: Member

Groups: Registered
Joined: 29/08/2010(UTC)
Posts: 14
Location: Buenos Aires

Your're right about FunctionSection(s) but the debugger doesnt recognize de name without the "s".

Can you upload the class.vb from the example? Because all that i need is a working trivial plugin and then change the code.

Thanks
Offline maweilian  
#14 Posted : 19 April 2011 22:45:22(UTC)
maweilian


Rank: Advanced Member

Groups: Registered
Joined: 09/01/2010(UTC)
Posts: 102
Man
United States
Location: Oregon, USA

Was thanked: 5 time(s) in 5 post(s)
What version of Smath are you using? This is important because the tutorial will not work if you are using a particular version. Please check and let us know. It will be under Help --> About Smath Studio.

Edited by user 19 April 2011 22:46:54(UTC)  | Reason: Not specified

Will Massie
Mechanical Engineer
Oregon, USA
Offline ing.sosa  
#15 Posted : 19 April 2011 23:10:06(UTC)
ing.sosa


Rank: Member

Groups: Registered
Joined: 29/08/2010(UTC)
Posts: 14
Location: Buenos Aires

My version is 89.8, i get the trivial plugin working with this line:

New TermInfo("dg", TermType.Function, "(num, dig) - Devuelve num con dig dígitos significativos", FunctionSections.Unknown, True)

But still having the same problem with the "store":

Dim num As Term() = Decision.Preprocessing(args(0), Store)

it says:

store is a type and cant be used as an expresion!!! Any idea?
Offline maweilian  
#16 Posted : 19 April 2011 23:16:13(UTC)
maweilian


Rank: Advanced Member

Groups: Registered
Joined: 09/01/2010(UTC)
Posts: 102
Man
United States
Location: Oregon, USA

Was thanked: 5 time(s) in 5 post(s)
The tutorial, as written, will not work for version 89.8. Andrey is in the process of making changes to the API in the 89.8 beta version. I would recommend using the 89.0 stable version for writing plugins at this point until we learn from him what changes have been made. When that time comes, the tutorial will be updated to reflect the changes.
Will Massie
Mechanical Engineer
Oregon, USA
Offline ing.sosa  
#17 Posted : 20 April 2011 06:01:41(UTC)
ing.sosa


Rank: Member

Groups: Registered
Joined: 29/08/2010(UTC)
Posts: 14
Location: Buenos Aires

Almost done in 89.8!

The problem with "store" was solved whis way:

Dim sto As New Store
Dim arg0 As Term() = Decision.Preprocessing(args(0), sto)
Dim arg1 As Term() = Decision.Preprocessing(args(1), sto)

Now the only problem remaining is this: i've created a function (dg) that rounds real numbers to a certain number of digits but not decimals (educational purposes in Numerical Analysis). The functions was working ok in stable 0.89 and now in 0.89.8, but in this version...

if i do dg(3,14159;3) = 3.14
if i do a:= 3.14159 and then dg(a;3) = NOTHING! (it says that a is not defined)

Does anyone here knows about any change in 89.8 that can explain this? i think there is a problem with de args()() parameter, but can solve this

Even when the function works ok in 0.89, i need to program inside functions, and 0.89.8 is the only version doing it!

Thanks,

Edited by user 20 April 2011 06:04:04(UTC)  | Reason: Not specified

Offline maweilian  
#18 Posted : 20 April 2011 19:44:50(UTC)
maweilian


Rank: Advanced Member

Groups: Registered
Joined: 09/01/2010(UTC)
Posts: 102
Man
United States
Location: Oregon, USA

Was thanked: 5 time(s) in 5 post(s)
Ok, I see.

Would you be willing to share your source code? It may help us help you better.

It would probably be better if you posted it as a link, instead of simply pasting it into your post. This wiki page gives help on how to add attachments to your postings: Notes on Using the Forum
Will Massie
Mechanical Engineer
Oregon, USA
Offline TheWizEd  
#19 Posted : 25 April 2011 03:16:13(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
ing.sosa,

I think there must be a typo in your coding. The function

Public Function ExpressionEvaluation(ByVal root As SMath.Manager.Term, ByVal args()() As SMath.Manager.Term, ByRef store As SMath.Manager.Store, ByRef result() As SMath.Manager.Term) As Boolean Implements IPluginLowLevelEvaluation.ExpressionEvaluation

which is the way SMath communicates with your plugin and passes a reference to "store" which contains all the variables that are input on the SMath tablet interface.

Now when you define a:=3.14159 and pass it as an argument to your function dg, SMath looks it up in "store" by its name "a" and can return its value which is a list of terms which could include units.

When you Dim sto in your program you've created a new empty store in which "a" does not reside.

I've been using SMath 0.89 but tried the beta. In the beta there are some minor differences in passing parameters to SMath core functions compared to the tutorial. The best way to find the differences is to examine the reference SMath dll in the VB environment.

Edited by user 25 April 2011 03:21:11(UTC)  | Reason: Not specified

Ed
Offline TheWizEd  
#20 Posted : 29 April 2011 16:45:47(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
ing,sosa,

I took a closer look at your post and realized it is a typo.

Change uppercase "Store" to lowercase "store".

Dim num As Term() = Decision.Preprocessing(args(0), Store)

"Store" is the SMath class name. "store" is the variable passed to function "ExpressionEvaluation".

Good luck.
Ed
Users browsing this topic
Guest
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.