0
|
5724 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# How to fix a procedure?

Posted 10 years ago
 Help me, please! There's the procedure operation[f_]. It works correctly and plot for functions:Cos,Sin. But, Unfortunately, it doesn't work for E^x and Log[E,x] and outputs errors, maybe because inputting not correct name of function or something else;(( What's the problem? spxsin = {-1, -0.35, 0.3, 0.95, 1.6, 2.375, 3.15, 3.925, 4.7, 5.025, 5.35, 5.675, 6}; spxcos = {-1, -0.75, -0.5, -0.25, 0, 0.775, 1.55, 2.325, 3.1, 3.825, 4.55, 5.275, 6}; spxlny = {-1, 0.75, 2.5, 4.25, 6}; spxey = {-1, 0.75, 2.5, 4.25, 6}; operation[f_] := Block[{data}, data = Table[{x, f[x]}, {x, -1, 6, 0.1}]; Graphics[{Thick, Blue, Line[data], Green, Table[Point[{spx[­[i]], f[spx[­[i]]]}], {i, 1, Length[spx]}], Pink, Opacity[.7], Table[Rectangle[{spx[­[i]], f[spx[­[i]]]}, {spx[­[i + 1]], f[spx[­[i + 1]]]}], {i, 1, Length[spx] - 1}] }, Axes -> True]] Which[ f == Sin, spx := spxsin, f == Cos, spx := spxcos, f == E^x , spx := spxlny, f == Log, spx := spxey] operation[Sin] operation[Cos] operation[E^x] operation[Log] 
3 Replies
Sort By:
Posted 10 years ago
 What exactly is wrong because I can't see any prob. It evaluates just fine for me. Perhaps you could explain what you were expecting to receive as output and what you actually get?
Posted 10 years ago
 Thanks! Exp works! but unfortunately, Log doesn't work, though I edited spxey = {0.75, 2.5, 4.25, 6}; and data = Table[{x, f[x]}, {x, 1, 6, 0.1}]; Can You help me?
Posted 10 years ago
 The mathematica function for the exponential is Exp[]. 1.1. Evaluating E^x//FullForm should show you that the head of this expression is not Exp but Power 1.2. Defining the exponential function in a similar fashion like you did, would require something like (E^#)& (probably, I haven't tested it) The problem you are having with Log[] is because the logarithm is not defined for negative input values while your spxey[[1]]==-1 hope that helps