# Lab #2 - Solutions

## Introduction

Back to lab exercises.

Back to the top

## Exercise 1

>> f = @(x) 4*x - 12
f =

@(x)4*x-12



Back to the top

## Exercise 2

>> f = @(x) tanh(x/10)
f =

@(x)tanh(x/10)



Back to the top

## Exercise 3

>> f = @(x) -2*(x + 3)^2 + 5
f =

@(x)-2*(x+3)^2+5



Back to the top

## Exercise 4

>> h = @(x) (3*x^3 - 1)/(x^2 + 3)
h =

@(x)(3*x^3-1)/(x^2+3)



Back to the top

## Exercise 5

>> g = @(y) y*exp(-y)
g =

@(y)y*exp(-y)



Back to the top

## Exercise 6

>> s = @(t) cos(t)
q  = @(t) 1/(s(t)^2 + 1)
s =

@(t)cos(t)

q =

@(t)1/(s(t)^2+1)



Back to the top

## Exercise 7

>> w = @(x) exp(-10*(x-2).^2)
w =

@(x)exp(-10*(x-2).^2)



Back to the top

## Exercise 8

>> R = @(x) (x + 2)^(sin(pi*x))
R =

@(x)(x+2)^(sin(pi*x))



Back to the top

## Exercise 9

>> T = @(x,y) 5/x^2 - 1 + y + 0.5*x^2/y
T =

@(x,y)5/x^2-1+y+0.5*x^2/y



Back to the top

## Exercise 10

>> f = @(x) cos(x)
g = @(x) x^2
h = @(x) f(x)*g(x)
fp = @(x) -sin(x)
gp = @(x) 2*x
hp = @(x) f(x)*gp(x) + fp(x)*g(x)
f =

@(x)cos(x)

g =

@(x)x^2

h =

@(x)f(x)*g(x)

fp =

@(x)-sin(x)

gp =

@(x)2*x

hp =

@(x)f(x)*gp(x)+fp(x)*g(x)



Back to the top

## Get the code

Do you want to try the above code fragments on your own? Download the Matlab script that produces this page here. (lab_2_solns.m) Published with MATLAB® 8.2