Matlab Programming(Need help with the last couple of details)

  • Thread starter Thread starter ialan731
  • Start date Start date
  • Tags Tags
    Couple Matlab
Click For Summary

Discussion Overview

The discussion revolves around a homework problem involving the calculation of the 2nd and 3rd degree Taylor polynomials for the function f(x)=ln(1+x) about the point a=0, as well as plotting these polynomials and the function over the interval -1

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant expresses confusion about an error message from Matlab regarding "Not enough input arguments" and seeks help in resolving it.
  • Another participant identifies a specific line of code as problematic, suggesting that the correct syntax for the natural logarithm function in Matlab is "y=log(1+x)".
  • A participant questions whether a dot is needed before or after the variable x in the logarithm function, indicating uncertainty about Matlab's syntax requirements.
  • Concerns are raised about the use of the factorial operator in the expressions for P2 and P3, with one participant suggesting that the factorial function should be used instead of the "!" symbol.
  • Another participant expresses confusion regarding the necessity of the factorial symbol in the Taylor polynomial expressions, questioning its relevance.
  • There is a reference to a general form of the Taylor series and derivatives for the function, but participants do not reach a consensus on the correct implementation of these concepts in the code.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the correct usage of the factorial operator in the context of the Taylor polynomials. There are differing opinions on whether the factorial symbol is appropriate in the expressions for P2 and P3, leading to unresolved questions about the implementation of the Taylor series in Matlab.

Contextual Notes

Participants reference the need to clarify the distinction between Matlab operators, such as the use of "." in expressions, and the proper syntax for mathematical functions, indicating potential misunderstandings in coding practices.

ialan731
Messages
25
Reaction score
0

Homework Statement



Okay, so I need some help with this Matlab program. I never learned Matlab, so I'm trying to do it as best as I can. The question is: Calculate the 2nd and 3rd degree Taylor polynomials for the function f(x)=ln(1+x) about the point a=0 Plot these polynomials and the function on the interval -1<x<3

Homework Equations



N/A

The Attempt at a Solution


This is what I have so far. I thought it was right, but Matlab said "Not enough input arguments." What does that mean, and I how do I fix it?
>> figure(1);clf;
x=[-1:.01:3];
y=log*(1+x);
P2= x-(x^2/2)!;
P3= x-(x^2/2)+(x^3/3)!;
figure(1);clf;
plot(x,y,x,P2,'--',x,P3,'-.')
legend('log*(1+x)','P_2','P_3')
xlabel('x')
title('The function and the 2^{nd} and ^{rd} order Taylor Polynomials')
figure(2);clf
plot(x,abs(y-P2),x,abs(y-P3),'--')
legend('log*(1+x)-P_2|','log*(1+x)-P_3|')
xlabel('x')
title('Errors in the two Taylor Polynomials')

Thanks in advance!:)
 
Physics news on Phys.org
Problem is with this line: "y=log*(1+x)". Can you spot it?
 
Honestly, no. There was an issue with that line before because I had put ln instead of log so I changed it. Is there supposed to be a . Before/after the x? I noticed that there's a lot of times where that's necessary.
 
log (natural log) is a function so it should be: "y=log(1+x)"
 
It's that simple? Wow I was looking for at least an hour, and I couldn't find the issue. Thank you so much!
 
I think you are also going to have a problem with the factorial operator. Missed that one--try the factorial() function. [edit-- you have some significant semantic issues with the factorial operation--does not make much sense]
 
Last edited:
What do you mean?
 
Well for example, the line:
P2= x-(x^2/2)!;

You are trying to take the factorial of an array of non-integers (not defined) using "!" (not a MATLAB operator). You might need to step back and detail what you are trying to do.
 
Oh so I would have to write out the factorial instead of simply putting !.
 
  • #10
I don't understand what the factorial symbol is doing in the expressions for P2 and P3. I don't think they belong there at all.
 
  • #11
But doesn't the equation call for a factorial? How else would it be done?
 
  • #12
Not sure what equation you are using. From page 4 of this link is the general form http://www.math.ufl.edu/~vatter/teaching/m8w10/m8l01.pdf

f = ln(1+x)
f' = 1/(1+x)
f'' = -1/(1+x)2
f''' = 2/(1+x)3

[edit-- also familiarize yourself with the distinction between the ".^" and the "^" operators]
 
Last edited by a moderator:
  • #13
lewando said:
Not sure what equation you are using. From page 4 of this link is the general form http://www.math.ufl.edu/~vatter/teaching/m8w10/m8l01.pdf

f = ln(1+x)
f' = 1/(1+x)
f'' = -1/(1+x)2
f''' = 2/(1+x)3

[edit-- also familiarize yourself with the distinction between the ".^" and the "^" operators]

I have to use the Taylor series so it's not just the derivative. And okay, will do.
 
Last edited by a moderator:

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
15
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 32 ·
2
Replies
32
Views
5K
  • · Replies 10 ·
Replies
10
Views
2K