HOW DO I DO THAT IN MATLAB SERIES?
In this series, I am answering questions that students have asked me about MATLAB.
Contents
TOPIC
How to use logarthemic and trignometric functions in MATLAB
SUMMARY
Language : Matlab 2008a; Authors : Sri Harsha Garapati, Daniel Miller, Autar Kaw; Mfile available at Last Revised : January 17, 2012; Abstract: This program shows you an how to use logarthemic functions and trignometric functions.
clc
clear all
INTRODUCTION
disp('ABSTRACT') disp(' This program shows you an how to use logarthemic functions and') disp(' trignometric functions and also how to use inverse trignometric') disp(' functions ') disp(' ') disp('AUTHOR') disp(' Sri Harsha Garapati, Daniel Miller and') disp('Autar K Kaw of http://autarkaw.wordpress.com') disp(' ') disp('MFILE SOURCE') disp(' http://numericalmethods.eng.usf.edu/blog/logsandtrig_sec001_blog.m') disp(' ') disp('LAST REVISED') disp(' January 17, 2012') disp(' ')
ABSTRACT This program shows you an how to use logarthemic functions and trignometric functions and also how to use inverse trignometric functions AUTHOR Sri Harsha Garapati, Daniel Miller and Autar K Kaw of http://autarkaw.wordpress.com MFILE SOURCE http://numericalmethods.eng.usf.edu/blog/logsandtrig_sec001_blog.m LAST REVISED January 17, 2012
INPUTS
a=4; %Input variable, a b=5; % Input variable,b c=2.4; % Input Vatiable,c ang =30; %Input variable"ang", representing angle given in degrees d=0.87; % side measurement 1 e=0.5; % side measurement 2
DISPLAYING INPUTS
disp('INPUTS') fprintf(' The input number a is %g \n',a) fprintf(' The input number b is %g \n',b) fprintf(' The input number c is %g \n',c) fprintf(' The input angle is %g \n',ang) fprintf(' The input number d is %g \n',d) fprintf(' The input number e is %g \n',e)
INPUTS The input number a is 4 The input number b is 5 The input number c is 2.4 The input angle is 30 The input number d is 0.87 The input number e is 0.5
THE CODE
Natural log of variable a (command is log)
alog=log(a); % natural log % Logs with a base of 10 of variable b (command is log10) l10b=log10(b); % log base 10 % exp function (the command is exp) f=exp(c); % exp raised to the 2.4 % trig functions (angle measurement input in radians) angr=ang*(pi/180); %convert to radians sin30=sin(angr); %sine command cos30=cos(angr); %cosine command tan30=tan(angr); %tangent command % inverse trig functions invsin=asin(d); % inverse sine invcos=acos(e); % inverse cosine
DISPLAYING OUTPUTS
disp(' ') disp('OUTPUTS') fprintf(' The natural log of %g is %g\n',a,alog) fprintf(' The log (base 10) of %g is %g\n',b,l10b) fprintf(' e^%g is %g\n',c,f) fprintf(' sin(%g) = %g\n',angr,sin30) fprintf(' cos(%g) = %g\n',angr,cos30) fprintf(' tan(%g) = %g\n',angr,tan30) fprintf(' The inverse sine of %g is %g\n',d,invsin) fprintf(' The inverse cosine of %g is %g\n',e,invcos)
OUTPUTS The natural log of 4 is 1.38629 The log (base 10) of 5 is 0.69897 e^2.4 is 11.0232 sin(0.523599) = 0.5 cos(0.523599) = 0.866025 tan(0.523599) = 0.57735 The inverse sine of 0.87 is 1.0552 The inverse cosine of 0.5 is 1.0472