×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# mathematical function

## mathematical function

(OP)
Hello

I'm a lisp newbie, trying, to write some mathematical function in Common Lisp.

Ich would like to create simple mathematical function like a line in form of y = mx + b or a curve.

Goal is, to get the points from x=0 with x = x+5 till a a given limit.
Is there any way I can create mathematical Functions with iteration like DOTIMES or something like that?

Thank you very much!

### RE: mathematical function

Here is an example:
function.lsp

#### CODE

; *** functions ***

(defun y (x)
; function y = m*x + b
(let
; define coefficients: m, b
((m 2)(b 5))
; return value: m*x + b
(+ (* m x) b)))

(defun print_function (fname point)
; print the value of a given function in the given point
; for example:
;   (print_function 'sqrt 2)
; prints
;   SQRT(2)=1.4142135
(format t "~A(~A)=~A~%" fname point (funcall fname point)))

; *** main program ***
(setq x_min 0) ; starting value
(setq x_max 100) ; ending value
(setq x_step 5) ; step
; print the function values in a loop
(setq x x_min)
(loop
(print_function 'y x) ; print the value y(x)
(setq x (+ x x_step)) ; increment: x = x + x_step
(when (> x x_max) (return)) ; end the loop when x > x_max
)
Output:

#### CODE

C:\>clisp function.lsp
Y(0)=5
Y(5)=15
Y(10)=25
Y(15)=35
Y(20)=45
Y(25)=55
Y(30)=65
Y(35)=75
Y(40)=85
Y(45)=95
Y(50)=105
Y(55)=115
Y(60)=125
Y(65)=135
Y(70)=145
Y(75)=155
Y(80)=165
Y(85)=175
Y(90)=185
Y(95)=195
Y(100)=205

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!