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

In summary, the problem was with the 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.
  • #1
ialan731
25
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
  • #2
Problem is with this line: "y=log*(1+x)". Can you spot it?
 
  • #3
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.
 
  • #4
log (natural log) is a function so it should be: "y=log(1+x)"
 
  • #5
It's that simple? Wow I was looking for at least an hour, and I couldn't find the issue. Thank you so much!
 
  • #6
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:
  • #7
What do you mean?
 
  • #8
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.
 
  • #9
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 [Broken]

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 [Broken]

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:

1. What is Matlab programming?

Matlab programming is a high-level programming language and interactive environment used for numerical computation, data analysis, and visualization. It is widely used in scientific research, engineering, and other fields that require complex mathematical and statistical operations.

2. What are the benefits of using Matlab?

There are several benefits of using Matlab for programming, including its user-friendly interface, built-in functions for complex mathematical operations, and its ability to handle large amounts of data. It also has a wide range of toolboxes available for different applications, making it a versatile programming language.

3. How can I get started with Matlab programming?

To get started with Matlab programming, you can download the software from the MathWorks website and follow the installation instructions. There are also many online tutorials and resources available to help beginners learn the basics of Matlab and start coding.

4. Are there any limitations to Matlab programming?

While Matlab is a powerful programming language, it does have some limitations. For example, it is not a good choice for developing large-scale or complex software applications. It also has a higher learning curve compared to other programming languages, making it more difficult for beginners to pick up.

5. Can I use Matlab for machine learning and artificial intelligence?

Yes, Matlab has a variety of tools and functions for machine learning and artificial intelligence applications. These include built-in algorithms for classification, regression, and clustering, as well as deep learning frameworks such as TensorFlow and Keras. Many researchers and data scientists use Matlab for developing and implementing machine learning models.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
914
  • Engineering and Comp Sci Homework Help
Replies
2
Views
764
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
819
  • Engineering and Comp Sci Homework Help
Replies
1
Views
817
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
705
  • Engineering and Comp Sci Homework Help
Replies
32
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
753
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
Back
Top