Ask your own question, for FREE!
Mathematics 49 Online
OpenStudy (raffle_snaffle):

% MATLAB contains functions to calculate the natural logarithm (log), the % logarithm to the base 10 (log10), and the logarithm to the base 2 % (log2). However, if you want to find a logarithm to another base - for % example, base b - you'll have to do the math yourself with the formula % y = logb(x,b) y = log10(4)./log10(2) % What is the logb of 10 when b is defined from 1 to 10 in increments of % 1? l = 1:1:10; % L = logb(x,b) L = log10(x)./log10(l)

OpenStudy (raffle_snaffle):

on the 2nd part.

OpenStudy (raffle_snaffle):

@zepdrix

OpenStudy (raffle_snaffle):

l is a vector

OpenStudy (jdoe0001):

so... what's the question? again

OpenStudy (jdoe0001):

and yes, if you're referring to other log bases, you'd need to use the "change of base rule" \(\Large log_{\color{red}{ a}}{\color{blue}{ b}}\implies \cfrac{log_{\color{olive}{ c}}{\color{blue}{ b}}}{log_{\color{olive}{ c}}{\color{red}{ a}}}\) where "c" can be anything, so long, is the same above and below so, you can use "e" or base 10

OpenStudy (raffle_snaffle):

2 = log10(x) <==> 0 = log2(x) I am trying to understand the math here.

OpenStudy (raffle_snaffle):

wait does base refer to c or b or a?

OpenStudy (jdoe0001):

base is the "subscript" letter dropped down

OpenStudy (raffle_snaffle):

okay so the two equations above are equal? Because when we have logb(x) = log10(4)/log10(2) = 2

OpenStudy (raffle_snaffle):

logb(x) = 2

OpenStudy (phi):

exactly what are you trying to understand?

OpenStudy (raffle_snaffle):

still trying to understand logb(x) = log(4)/log(2) ? that is 2, but does the 2 represent the new basis for logb(x)?

OpenStudy (phi):

it would be clearer if you wrote log_b(x) to mean log base "b" then the formula would be log(x)/log(b) where log is a "known" base (i.e. "e" or 10)

OpenStudy (raffle_snaffle):

% What is the logb of 10 when b is defined from 1 to 10 in increments of % 1?

OpenStudy (jdoe0001):

well, bear in mind that, when the base is skipped, "10" is assumed so log(x) really means \(\bf log_{10}(x)\) so \(log_{\color{red}{ a}}{\color{blue}{ b}}\implies \cfrac{log_{\color{olive}{ c}}{\color{blue}{ b}}}{log_{\color{olive}{ c}}{\color{red}{ a}}} \\ \quad \\ \quad \\ log_{\color{red}{ 4}}{\color{blue}{ 2}}\implies \cfrac{log{\color{blue}{ (2)}}}{log{\color{red}{ ( 4)}}}\implies \cfrac{log_{\color{olive}{ 10}}{\color{blue}{ (2)}}}{log_{\color{olive}{ 10}}{\color{red}{ ( 4)}}}\)

OpenStudy (phi):

Inf 3.3219 2.0959 1.6610 1.4307 1.2851 1.1833 1.1073 1.0480 1.0000

OpenStudy (raffle_snaffle):

Are they saying b is the vector? b = 1:1:10

OpenStudy (raffle_snaffle):

am I looking for another logarithm when the bases b = 1:1:10

OpenStudy (phi):

yes, they are for different bases (though why they ask for base 1 is a bit mysterious, because we can't do base 1)

OpenStudy (raffle_snaffle):

but I was making a vector so b = starting:increment:ending

OpenStudy (raffle_snaffle):

% What is the logb of 10 when b is defined from 1 to 10 in increments of % 1? be is defined as a matrix

OpenStudy (phi):

yes, I did >> aa= logb(10,1:10) aa = Columns 1 through 9: Inf 3.3219 2.0959 1.6610 1.4307 1.2851 1.1833 1.1073 1.0480 Column 10: 1.0000

OpenStudy (raffle_snaffle):

I forgot about that...

OpenStudy (phi):

**% What is the logb of 10 when b is defined from 1 to 10 in increments of % 1?** I interpret that to mean they want \[ \log_1(10), \log_2(10), \log_3(10), ...\]

OpenStudy (raffle_snaffle):

that makes sense. I interpreted it wrong.=/

OpenStudy (phi):

you did it correctly up top *** l = 1:1:10; % L = logb(x,b) L = log10(x)./log10(l) ****

OpenStudy (raffle_snaffle):

what you are saying is logb(10, 1:10) is the same as what I did on the top but using another method?

OpenStudy (phi):

though I would stay away from variables l (looks too much like 1, and some day you will regret it) ii would be better or even log10(x) ./ (1:10)

OpenStudy (phi):

did you create logb.m file that contains the lines % y = logb(x,b) % returns log_base_b(x) function y= logb(x,b) y= log(x)./log(b); ?

OpenStudy (raffle_snaffle):

I will keep that in mind. I used "l" because I was thinkg L = l but I will be sure to stay away from l since it looks like 1

OpenStudy (raffle_snaffle):

log10(x) ./ (1:10) <==== does it automatically know it's incrementing by one?

OpenStudy (phi):

yes, you can test it. type 1:10 return in matlab

OpenStudy (raffle_snaffle):

why do i need did you create logb.m file that contains the lines % y = logb(x,b) % returns log_base_b(x) function y= logb(x,b) y= log(x)./log(b);

OpenStudy (raffle_snaffle):

oh so function y = logb(x,b) is a function huh?

OpenStudy (raffle_snaffle):

function Add new function. New functions may be added to MATLAB's vocabulary if they are expressed in terms of other existing functions. The commands and functions that comprise the new function must be put in a file whose name defines the name of the new function, with a filename extension of '.m'. At the top of the file must be a line that contains the syntax definition for the new function. For example, the existence of a file on disk called STAT.M with: function [mean,stdev] = stat(x) %STAT Interesting statistics. n = length(x); mean = sum(x) / n; stdev = sqrt(sum((x - mean).^2)/n); defines a new function called STAT that calculates the mean and standard deviation of a vector. The variables within the body of the function are all local variables. See SCRIPT for procedures that work globally on the work- space. A subfunction that is visible to the other functions in the same file is created by defining a new function with the function keyword after the body of the preceding function or subfunction. For example, avg is a subfunction within the file STAT.M:

OpenStudy (phi):

I assume that is what they want. You don't have to for this simple problem, but it's not hard to do, and it's convenient

OpenStudy (raffle_snaffle):

okay. I didn't know about this command until now.

OpenStudy (raffle_snaffle):

% y = logb(x,b) % returns log_base_b(x) <==== this is a comment? function y= logb(x,b) y= log(x)./log(ii); ^^^I used this code letting ii = 1:1:10 It is not working

OpenStudy (phi):

what does it do?

OpenStudy (phi):

did you create a file named logb.m ?

OpenStudy (raffle_snaffle):

% What is the logb of 10 when b is defined from 1 to 10 in increments of % 1? % L = logb(x,b) ii = 1:1:10; function y = logb(x,b) L = log10(x)./log10(ii) ^^^This is what I have now Error: File: Homework2.m Line: 15 Column: 2 Function definitions are not permitted in this context.

OpenStudy (raffle_snaffle):

No I didn't create a file name logb.m Why does it need it's own file?

OpenStudy (phi):

yes, you need a complete separate file (with that name) in the local directory matlab has a search path to look for file names, and it will start by looking in your local director. (the one you see if you do dir )

OpenStudy (raffle_snaffle):

I am writing all of this in a script btw

OpenStudy (raffle_snaffle):

not in the command window

OpenStudy (phi):

that's ok. the script will have its own file, with a name like homework.m

OpenStudy (raffle_snaffle):

so I need to make a complete separate script with this info % y = logb(x,b) % returns log_base_b(x) function y= logb(x,b) y= log(x)./log(b); and then go back to homework.m to run the new function? So the function command has to have its own m file huh?

OpenStudy (phi):

yes. try it

OpenStudy (raffle_snaffle):

Error: File: Homework2.m Line: 15 Column: 2 Function definitions are not permitted in this context.

OpenStudy (raffle_snaffle):

Okay so I made a new script named logb(x) with this info in int % y = logb(x,b) % returns log_base_b(x) function y= logb(x,b) y= log(x)./log(b); Then I went back to the other m file called homework2 which has this info % What is the logb of 10 when b is defined from 1 to 10 in increments of % 1? % L = logb(x,b) ii = 1:1:10; function y = logb(x,b); L = log10(x)./log10(ii)

OpenStudy (phi):

the new file should be called logb.m and in your script you type logb(10,2) for example

OpenStudy (raffle_snaffle):

which script homework? Let me go back and rename the file logb

OpenStudy (phi):

don't forget the .m extension

OpenStudy (raffle_snaffle):

it automatically puts the .m at the end after renaming it logb

OpenStudy (phi):

ok, now in your homework script you can put in logb(10,2) to calculate log_2(10) as a test, also put in log2(10)

OpenStudy (raffle_snaffle):

Error in Homework2 (line 15) logb(10,2)

OpenStudy (raffle_snaffle):

% What is the logb of 10 when b is defined from 1 to 10 in increments of % 1? % L = logb(x,b) logb(10,2) log2(10) ^^^in homework2 script % y = logb(x,b) % returns log_base_b(x) function y= logb(x,b) y= log(x)./log(b); ^^^in logb.m script

OpenStudy (phi):

in your command window, type which logb

OpenStudy (raffle_snaffle):

which logb logb is a variable.

OpenStudy (phi):

type clear logb

OpenStudy (raffle_snaffle):

okay said clear logb and then i ran the program still getting an error

OpenStudy (phi):

perhaps you are setting logb inside your script? if you do dir do you see the logb.m file ? if you put clear logb logb(10,2) in your command window, does it work ?

OpenStudy (raffle_snaffle):

%% 3.2 % MATLAB contains functions to calculate the natural logarithm (log), the % logarithm to the base 10 (log10), and the logarithm to the base 2 % (log2). However, if you want to find a logarithm to another base - for % example, base b - you'll have to do the math yourself with the formula % y = logb(x,b) %y = log10(4)./log10(2) % What is the logb of 10 when b is defined from 1 to 10 in increments of % 1? % L = logb(x,b) log(10,2) log2(10)

OpenStudy (raffle_snaffle):

This is what I have in my script. I surpressed the %y = log10(4)./log10(2) because that was from the last question. >> logb(10,2) Undefined function or variable 'logb'. Did you mean: >> log(10,2) Index exceeds matrix dimensions. ^^^What I get when I type logb(10,2) in command window

OpenStudy (phi):

ok, in the command window, type which logb

OpenStudy (raffle_snaffle):

>> which logb 'logb' not found.

OpenStudy (phi):

now type dir

OpenStudy (raffle_snaffle):

. RStudio.lnk .. Shortcut to SecureDownloadManager.exe.lnk .RData desktop.ini Dropbox.lnk

OpenStudy (phi):

it looks like you are not in the directory where you put logb.m

OpenStudy (raffle_snaffle):

>> dir . Homework1.m lab02.m weather_data.xls .. Homework2.m logb.m.m

OpenStudy (phi):

ok, that looks better. I would rename logb.m.m to logb.m

OpenStudy (raffle_snaffle):

>> Homework2 Index exceeds matrix dimensions. Error in Homework2 (line 15) log(10,2)

OpenStudy (phi):

yes log(10,2) is wrong. log is a matlab function and it only wants 1 number logb(10,2) should work but first, which logb does that find logb ? dir does that show logb.m file >> logb(10,2) does that work ?

OpenStudy (raffle_snaffle):

>> Homework2 ans = 3.3219 r = 0.9000

OpenStudy (raffle_snaffle):

Ignore the r

OpenStudy (raffle_snaffle):

% What is the logb of 10 when b is defined from 1 to 10 in increments of % 1? % L = logb(x,b) logb(10,2) log2(10) >> Homework2 ans = 3.3219 ans = 3.3219

OpenStudy (raffle_snaffle):

That is pretty neat.

OpenStudy (phi):

success now you can do logb(10,1:10)

OpenStudy (raffle_snaffle):

ans = Columns 1 through 9 Inf 3.3219 2.0959 1.6610 1.4307 1.2851 1.1833 1.1073 1.0480 Column 10 1.0000

OpenStudy (raffle_snaffle):

one last question in logb(10,1:10) the (base, first, end)

OpenStudy (raffle_snaffle):

does the first 10 represent the base?

OpenStudy (phi):

no, the 10 is x in \[ \log_b(x) \] the 1:10 are the bases

OpenStudy (raffle_snaffle):

okay got it.

OpenStudy (phi):

if you save the answer aa= logb(10, 1:10) then (1:10).^aa should return 10's (except for the first one)

OpenStudy (raffle_snaffle):

yep it return to 10. Well I am out. Thanks for showing me how to use the command function. I will probably have to use that command later in this course. later

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!