Effacer les filtres
Effacer les filtres

I have a Maclaurin Series, how do I calculate it?

3 vues (au cours des 30 derniers jours)
Mark Dillon
Mark Dillon le 9 Août 2015
Modifié(e) : Image Analyst le 28 Déc 2021
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...

Réponses (4)

Walter Roberson
Walter Roberson le 9 Août 2015

Star Strider
Star Strider le 9 Août 2015
A one-line version:
log_1_minus_x = @(x,n) sum(-x.^(1:n)./(1:n));

Image Analyst
Image Analyst le 9 Août 2015
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.

Eram Khan
Eram Khan le 28 Déc 2021
Modifié(e) : Image Analyst le 28 Déc 2021
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

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by