## 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!

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

function.lsp

## CODE

(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

)

## CODE

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