I have a Maclaurin Series, how do I calculate it?
5 次查看(过去 30 天)
显示 更早的评论
The Series is:
log(1-x) = -x/1 - x^2/2 - x^3/3 - x^4/4...
I need to write a script that prompts the use to enter a value for x, and calculate it to the first 15 terms.
My instructor has not gone over this in his notes so I have know idea what to do...
0 个评论
回答(4 个)
Image Analyst
2015-8-9
Here's a snippet that may be helpful for you to ask for the value of x and the number of terms to sum:
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter a value';
userPrompt = {'Enter x : ', 'Enter number of terms: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check for a valid number.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
A for loop is simply
theSum = 0
for k = 1 : numberOfTerms
theSum = theSum + ...........
end
You should be able to take it from there. Just put in the expression for the kth term.
0 个评论
Eram Khan
2021-12-28
编辑:Image Analyst
2021-12-28
h= input('enter number')
n= input('enter iteration')
m=0;
s=0;
while m<=n
K = (h/fact(m)) ^ m;
s = s + k;
m = m + 1;
end
Disp(s)
-------- fact is a function doing factorial for any number, such as "factorial()" which is a built-in function of MATLAB.
It is for exponential Maclaurin series
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!