Error in calculation

Error in calculation - Сообщения

#1 Опубликовано: 28.01.2012 16:56:25
jamlatino

jamlatino

0 сообщений из 4 понравились пользователям.

Группа: User

I have gone crazy trying to figure out what I´m doing wrong but I came to the conclusion that there must be some kind of bug because I try to do a calculation in different ways and I get different results. I don´t know how to attach a file or insert an image of what I mean, can someone help?
#2 Опубликовано: 28.01.2012 17:34:24
Radovan Omorjan

Radovan Omorjan

325 сообщений из 2052 понравились пользователям.

Группа: Moderator

Hello,
Wrote

I have gone crazy trying to figure out what I´m doing wrong but I came to the conclusion that there must be some kind of bug because I try to do a calculation in different ways and I get different results. I don´t know how to attach a file or insert an image of what I mean, can someone help?


1. Try to use "Live" version here. Use "Upload" and upload your *.sm file. If everything goes well - get the link and put it here. Pay attention that there are restrictions regarding Live version - no plots, complicated programming structures etc. Actually, if Live version can not "swallow" your file - error will be issued.

2.Register to some free hosting service like, say, dropbox. You will get free 2GB space initially (never expires). There you can have your folders, upload files etc. Put your files in the dropbox "Public" folder. Get the links to the files ( right mouse click and get the "Public link" ) and put those links in your posts here on the Forum by using "Insert image" if there is a link to an image, or "Create link" if there is a link to a file - as easy as that.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#3 Опубликовано: 28.01.2012 20:14:08
jamlatino

jamlatino

0 сообщений из 4 понравились пользователям.

Группа: User

Thanks so much for your help, here's the link to the file with the error I mentioned

Error
#4 Опубликовано: 29.01.2012 04:34:17
Radovan Omorjan

Radovan Omorjan

325 сообщений из 2052 понравились пользователям.

Группа: Moderator

Hello,

It seems there is a bug in SMath, or at least something we must take care off. Here is the expression.
[MATH=eng]GAr(A,G,i,n)←A*({(1+i)^n-1}/{(1+i)^n*i})+G/i*({(1+i)^n-1}/{(1+i)^n*i}-n/{(1+i)^n})[/MATH]
Now, if the Optimization|Symbolic is set, here is the result - it seems the wrong one:
[MATH=eng]GAr(1000,100,0.04,5)=4453.1911[/MATH]
Now, if the Optimization|Numeric or None is set, it is the right one:
[MATH=eng]GAr(1000,100,0.04,5)=5307.2893[/MATH]

On the other hand, apparently strange thing happen when you exchange the order of regions
1. First expressions then assignment - wrong

2. First assignment then expressions - right


Actually, I found the reason. The problem is in variable "i" - imaginary unit , but I still believe this is wrong regarding the function definition. Just change everywhere the variable "i" into something else and there would be no problem. For instance:

[MATH=eng]GAr(A,G,ii,n)←(A*({(1+ii)^n-1}/{(1+ii)^n*ii}))+(G/ii*({(1+ii)^n-1}/{(1+ii)^n*ii}-n/{(1+ii)^n}))[/MATH]
[MATH=eng]GAr(1000,100,0.04,5)=5307.2893[/MATH]
Regardless the Optimization set.

On the other hand, when you did it step by step - the imaginary unit was used and not the variable you defined AFTER the expressions defined. You would have seen this by putting the mouse over the expression (symbolic value) if the imaginary unit would have been replaced by its value or:
[MATH=eng]f1—(1+sqrt(-1))^n[/MATH]
instead of:
[MATH=eng]f1—(1+i)^n[/MATH]


Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#5 Опубликовано: 29.01.2012 09:38:40
jamlatino

jamlatino

0 сообщений из 4 понравились пользователям.

Группа: User

Thanks a lot, I changed i to ii as you suggested and got the right answer, but still, is there a bug in the program?
#6 Опубликовано: 29.01.2012 09:59:06
Radovan Omorjan

Radovan Omorjan

325 сообщений из 2052 понравились пользователям.

Группа: Moderator

Yes, I think it is a bug regarding function definition and using variable "i" as a fictive argument. The safest way is not to use it as an argument in function definition

Regards,
Radovan

EDIT:
Actually, there is a solution. Define function with line(). Often, this will be the only way we can define a function. Based on my experience, it seems that the safest way is to define even a single line function by using line() environment. Maybe a bit confusing, but I do not know whay is that working this way:
[MATH=eng]f(i)←line(i^2,1,1)[/MATH]
[MATH=eng]f(100)=10000[/MATH]

Contrary to the wrong one

[MATH=eng]f(i)←i^2[/MATH]
[MATH=eng]f(100)=-1[/MATH]
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений