Non-functions plot app...
Hi everybody!! I have a question: is it possible to code a plot app that can also plot non-functions, like an ellipsis or a circle, on the plane, given its equation?? What should i do to solve the equation and get the points? I'm assuming not to only draw those curves but even complex curves like beziers curves, etc..
Re: Non-functions plot app...
Quote:
Originally Posted by poggo
Hi everybody!! I have a question: is it possible to code a plot app that can also plot non-functions, like an ellipsis or a circle, on the plane, given its equation?? What should i do to solve the equation and get the points? I'm assuming not to only draw those curves but even complex curves like beziers curves, etc..
I'm not quite sure what your problem is. Can you be a bit more explicit? Plotting a function given its equation shouldn't be too difficult, just choose an interval for the independent variable, select a step, calculate the function value and place this in a loop where you include some code for plotting.
As for circles and other closed curves, the best you could do is use polar or parametric coordinates, otherwise you have 2 (or more) function values for every single value of the independent variable.
Re: Non-functions plot app...
My fault. I meant how can i solve that equations with 2 variables?? And if these variables are cubic? Or fourth powered?? How do i find solutions of an user-input equation?
Re: Non-functions plot app...
Quote:
Originally Posted by poggo
My fault. I meant how can i solve that equations with 2 variables?? And if these variables are cubic? Or fourth powered?? How do i find solutions of an user-input equation?
It depends on what type of equations. If they are linear it's quite easy. Otherwise you'll have to look into numerical methods. However, different types of equations may require different recipes. Can you post a few samples?
Re: Non-functions plot app...
Yes... for example a circle: x^2+y^2+3x-4y+5=0
Or an ellipsis: x^2/12 + y^2/25=0
Do you need any other examples?
Anyway, i mean curves like these, or even like cosh, sinh, tanh, etc...
Re: Non-functions plot app...
The circle is not too hard to solve:
x2+y2+3x-4y+5=0
Compare this to the general equation of a circle with center at (a,b) and radius R:
(x - a)2 + (y - b)2 = R2
x2 -2ax +a2 + y2 -2by + b2 - R2 = 0
Identifying terms:
-2a = 3
2b = 4
a2 + b2 - R2 = 5
From this you get
a = -3/2
b = 2
R = Sqrt(5) / 2
The presumed ellipse is not such:
x2/12 + y2/25=0
The right term should be 1 !!! If this is the case (i.e. you mistranscribed it) then the right equation is:
x2/12 + y2/25 = 1
from which:
y2/25 = 1 - x2/12
y2 = 25(1 - x2/12)
y = Sqrt[25(1 - x2/12)] = 5*Sqrt[1 - x2/12)]
As for other types of equations, each needs its own way to be dealt with.
Re: Non-functions plot app...
If, on the other hand, your trouble is getting from the string of an equation that a user has typed in a textbox to actually doing the calculation, then you'll need to program a calculator.
This thread might be of use...
zaza
Re: Non-functions plot app...
Quote:
Originally Posted by zaza
If, on the other hand, your trouble is getting from the string of an equation that a user has typed in a textbox to actually doing the calculation, then you'll need to program a calculator.
This thread might be of use...
zaza
I once programmed a calculator which parsed a user-input RPN string and evaluated the expression. Indeed, RPN is much easier to code!
Re: Non-functions plot app...
I made a application like what you are trying to do.
I had to use regression to figure out the y value once I had an x value....
for like the circle x^2+y^2=4
Here is a little sample of what it would be like...
VB Code:
For x as integer = -2 to 2
for y as integer = -10 to 10
If evaluate(x^2+y^2)=4 Then
StorePoint(x,y)
End if
next y
next x
I wouldn't suggest it, but maybe that will get you started...
If you need an application check out: http://www.peda.com/grafeq/
Nice quick application. Very useful/ easy & strait forward....
Maybe talk them into releasing their source....? <good luck>
Re: Non-functions plot app...
I didn't know about "evaluate", I assume it's a sub you coded yourself.
Re: Non-functions plot app...
Nope. Scripting control:
VBSCRIPT
VB Code:
Option Explicit
' Add a reference to Microsoft Script Control 1.0
Private Sub Form_Load()
Dim str1 As String
Dim dbl1 As Double
Dim x As New ScriptControl
Dim z%, a%, q$
z = 55
a = 24
q = "*"
x.Language = "vbScript"
MsgBox Format(x.Eval(z & q & a), "standard")
' ===============================================
str1 = "(5+50)*2/3"
dbl1 = (x.Eval(str1))
MsgBox dbl1
End Sub
JSCRIPT
VB Code:
Option Explicit
' Add a reference to Microsoft Script Control 1.0
Private Sub Form_Load()
Dim strExpression As String
Dim x As New ScriptControl
x.Language = "jScript"
strExpression = "unescape('%2F')"
MsgBox x.Eval(strExpression)
strExpression = "escape(':')"
MsgBox x.Eval(strExpression)
End Sub
Re: Non-functions plot app...
Quote:
Originally Posted by dglienna
Nope. Scripting control...
Gee, I wasn't aware that such a thing existed... what are these scripts used for, i.e. what can you do with them that couldn't be done in VB without?
Re: Non-functions plot app...
Quote:
Originally Posted by dglienna
Nope. Scripting control:
VBSCRIPT
VB Code:
Option Explicit
' Add a reference to Microsoft Script Control 1.0
Private Sub Form_Load()
Dim str1 As String
Dim dbl1 As Double
Dim x As New ScriptControl
Dim z%, a%, q$
z = 55
a = 24
q = "*"
x.Language = "vbScript"
MsgBox Format(x.Eval(z & q & a), "standard")
' ===============================================
str1 = "(5+50)*2/3"
dbl1 = (x.Eval(str1))
MsgBox dbl1
End Sub
JSCRIPT
VB Code:
Option Explicit
' Add a reference to Microsoft Script Control 1.0
Private Sub Form_Load()
Dim strExpression As String
Dim x As New ScriptControl
x.Language = "jScript"
strExpression = "unescape('%2F')"
MsgBox x.Eval(strExpression)
strExpression = "escape(':')"
MsgBox x.Eval(strExpression)
End Sub
...Which is the slowest imaginable way to do string math.
It's is useless for doing many evaluations at once. You'll need to find a bespoke, optimised string math evaluator.