Question
% exf1.m (Example 2.4) % Define a function, 'exf1', that evaluates e^x. % This function takes 'x' as an input argument and is % called
% exf1.m (Example 2.4) % Define a function, 'exf1', that evaluates e^x. % This function takes 'x' as an input argument and is % called either from the Command Window or from another % program. The resulting output, 'ex', is available to % be used in another program or in the Command Window. % In this example, term(n+1) is obtained from term(n) % by multiplying term(n) by x. % Note: e^x = 1 + x + x^2/2! + x^3/3! + x^4/4! + ... function ex = exf1(x) term(1)=1.0; for n=1:99 term(n+1)=term(n)*x; if abs(term(n+1))
% Example_2_5.m % This program uses the function exf1 (defined in % Example 2.4) in several arithmetic statements, i.e to % calculate w, y and z. In this program, the output is % sent to a file. clear; clc; fo=fopen('output.txt','w'); fprintf(fo,' x y w z '); fprintf(fo,'---------------------------------- '); for x=0.1:0.1:2.0 y=exf1(x); w=5*x*exf1(x); z=10*x/y; fprintf(fo,'%4.2f %8.3f %8.3f %8.3f ',x,y,w,z); end fclose(fo); --------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started