I have a Maclaurin Series, how do I calculate it?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
Respuestas (4)
  Star Strider
      
      
 el 9 de Ag. de 2015
        A one-line version:
log_1_minus_x = @(x,n) sum(-x.^(1:n)./(1:n));
0 comentarios
  Image Analyst
      
      
 el 9 de Ag. de 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.
0 comentarios
  Eram Khan
 el 28 de Dic. de 2021
        
      Editada: Image Analyst
      
      
 el 28 de Dic. de 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
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




