# EXPERIMENT 2: Working with logarithmic scales

Sometimes measurements have a wide range of values. For example, a single human cell weighs about 10^{-16} kg while a whale weights about 10^5 kg, a difference of 21 orders of magnitude! It would difficult to display data of this range on the same graph without using logarithmic scales.

Logarithmic scales also expose the structure of the data as the independent variable becomes large. This experiment explores how use logarithmic scales to reveal scaling relationships.

The experiment consists of three parts: Part a explores the behavior of polynomials, Part b explores the behavior of exponential functions and Part c explores the behavior of logarithmic functions when plotted using axes that various combinations of linear and logarithmic scales.

Part a: Scaling behavior of polynomials

Predict the behavior when polynomials are plotted:

• both axes use linear scales
• y uses a logarithmic scale and x uses a linear scale
• x uses a logarithmic scale and y uses a linear scale
• both axes use logarithmic scales</li>

Part b:Scaling behavior of exponential functions

Predict the behavior when logarithmic are plotted:

• both axes use linear scales
• y uses a logarithmic scale and x uses a linear scale
• x uses a logarithmic scale and y uses a linear scale
• both axes use logarithmic scales

Part a:Scaling behavior of logarithmic functions

Predict the behavior when logarithmic functions are plotted:

• both axes use linear scales
• y uses a logarithmic scale and x uses a linear scale
• x uses a logarithmic scale and y uses a linear scale
• both axes use logarithmic scales

In all cases, describe the results qualitatively --- e.g., "the graph is linear" or the "graph is concave down". If the graph is linear, predict the slope and/or intercept in terms of the function.

Why does the code for the logarithmic functions give a number of warnings?

What happens when lower order terms are included in the polynomial?

## Create data for 3 polynomials for points in the interval [0.1, 10]

```   x = 0.1:0.1:10;
y1 = polyval([1, 0], x);      % Evaluate y = x;
y2 = polyval([1, 0, 0], x);   % Evaluate y = x^2;
y3 = polyval([1, 0, 0, 0], x);   % Evaluate y = x^3;
```

## Plot the polynomials on an ordinary scale

```   figure
hold on
plot(x, y1, '.k');
plot(x, y2, '.b');
plot(x, y3, '.r');
title ('Three polynomials on an ordinary scale')
xlabel('x');
ylabel('y');
legend({'y = x', 'y = x^2', 'y = x^3'}, 'Location', 'Northwest')
```

## Plot the polynomials on a semilog y scale

```   figure
semilogy(x, y1, '.k', x, y2, '.b', x, y3, '.r');
title ('Three polynomials on a semilog y scale')
xlabel('x');
ylabel('y');
legend({'y = x', 'y = x^2', 'y = x^3'}, 'Location', 'Northwest')
```

## Plot the polynomials on a semilog x scale

```   figure
semilogx(x, y1, '.k', x, y2, '.b', x, y3, '.r');
title ('Three polynomials on a semilog x scale')
xlabel('x');
ylabel('y');
legend({'y = x', 'y = x^2', 'y = x^3'}, 'Location', 'Northwest')
```

## plot the polynomials on a log-log scale

```   figure
loglog(x, y1, '.k', x, y2, '.b', x, y3, '.r');
title ('Three polynomials on a loglog scale')
xlabel('x');
ylabel('y');
legend({'y = x', 'y = x^2', 'y = x^3'}, 'Location', 'Northwest')
```

## Create data for 3 exponential functions for points in the interval [0.1, 10]

```   x = 0.1:0.1:10;
y1 = exp(x);     % Evaluate y = e^{x};
y2 = exp(2*x);   % Evaluate y = e^{2x};
y3 = exp(3*x);   % Evaluate y = e^{3x};
```

## Plot the exponentials on an ordinary scale

```   figure
hold on
plot(x, y1, '.k');
plot(x, y2, '.b');
plot(x, y3, '.r');
title ('Three exponentials on an ordinary scale')
xlabel('x');
ylabel('y');
legend({'y = e^x', 'y = e^{2x}', 'y = e^{3x}'}, 'Location', 'Northwest')
```

## Plot the exponentials on a semilog y scale

```   figure
semilogy(x, y1, '.k', x, y2, '.b', x, y3, '.r');
title ('Three exponentials on a semilog y scale')
xlabel('x');
ylabel('y');
legend({'y = e^x', 'y = e^{2x}', 'y = e^{3x}'}, 'Location', 'Northwest')
```

## Plot the exponentials on a semilog x scale

```   figure
semilogx(x, y1, '.k', x, y2, '.b', x, y3, '.r');
title ('Three exponentials on a semilog x scale')
xlabel('x');
ylabel('y');
legend({'y = e^x', 'y = e^{2x}', 'y = e^{3x}'}, 'Location', 'Northwest')
```

## plot the exponentials on a log-log scale

```   figure
loglog(x, y1, '.k', x, y2, '.b', x, y3, '.r');
title ('Three exponentials on a loglog scale')
xlabel('x');
ylabel('y');
legend({'y = e^x', 'y = e^{2x}', 'y = e^{3x}'}, 'Location', 'Northwest')
```

## Create data for 3 exponential functions for points in the interval [0.1, 10]

```   x = 0.1:0.1:10;
y1 = log(x);     % Evaluate y = log(x);
y2 = log(2*x);   % Evaluate y = log(2x);
y3 = log(3*x);   % Evaluate y = log(3x);
```

## Plot the logarithms on an ordinary scale

```   figure
hold on
plot(x, y1, '.k');
plot(x, y2, '.b');
plot(x, y3, '.r');
title ('Three logarithms on an ordinary scale')
xlabel('x');
ylabel('y');
legend({'y = log(x)', 'y = log(2x)', 'y = log(3x)'}, 'Location', 'Northwest')
```

## Plot the logarithms on a semilog y scale

```   figure
semilogy(x, y1, '.k', x, y2, '.b', x, y3, '.r');
title ('Three logarithms on a semilog y scale')
xlabel('x');
ylabel('y');
legend({'y = log(x)', 'y = log(2x)', 'y = log(3x)'}, 'Location', 'Northwest')
```
```Warning: Negative data ignored
Warning: Negative data ignored
Warning: Negative data ignored
Warning: Negative data ignored
Warning: Negative data ignored
```

## Plot the logarithms on a semilog x scale

```   figure
semilogx(x, y1, '.k', x, y2, '.b', x, y3, '.r');
title ('Three logarithms on a semilog x scale')
xlabel('x');
ylabel('y');
legend({'y = log(x)', 'y = log(2x)', 'y = log(3x)'}, 'Location', 'Northwest')
```

## plot the logarithms on a log-log scale

```   figure
loglog(x, y1, '.k', x, y2, '.b', x, y3, '.r');
title ('Three logarithms on a loglog scale')
xlabel('x');
ylabel('y');
legend({'y = log(x)', 'y = log(2x)', 'y = log(3x)'}, 'Location', 'Northwest')
```
```Warning: Negative data ignored
Warning: Negative data ignored
Warning: Negative data ignored
Warning: Negative data ignored
Warning: Negative data ignored
```