Can someone help me with this question? I keep getting the error "Not enough input arguments. Error in assesment2question1 (line 5) for m = 1:N"
Mostra commenti meno recenti
The question I have is:
Consider the Maclaurin expansion: x/(1-x) = x + x^2 + x^3 + ...
Write a MATLAB function func(x,N) that returns the Maclaurin expansion using the first N terms. Use the function to plot, func(x,2), func(x,4) and func(x,8) on the same axes, for -0.5<x<0.5.
1 Commento
madhan ravi
il 9 Dic 2018
upload your function
Risposta accettata
Più risposte (1)
>> func = @(x,N) sum(bsxfun(@power,x,(1:N).'),1);
>> X = -0.5:0.1:0.5;
>> plot(X,func(X,2), X,func(X,4), X,func(X,8))
Giving:

Of course this would also be easy to write in a function file, if you wanted to:
function y = (x,N)
y = sum(bsxfun(@power,x,(1:N).'),1);
end
And just to make things clearer you can also add a legend, etc:
>> plot(X,func(X,2), X,func(X,4), X,func(X,8))
>> hold on
>> plot(X,X./(1-X),'*')
>> legend({'N=2','N=4','N=8','actual'})

Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
