tic
syms x y;
f(x) = (2.*x-1).*sin(pi.*x);
for i=1:25
y(i)=diff(f(x),i);
end
fun=matlabFunction(y');
x=-2:0.01:1;
result=fun(x);
maxres = max(result,[],2)
for i=1:25
if maxres(i)<0.001
break
end
end
someone can tell me the way to find max y(i) = diff (f(x),i) in every step and check it
if max(y(i))< 0.001 then stop the loop

 Accepted Answer

madhan ravi
madhan ravi on 24 Dec 2018
Edited: madhan ravi on 24 Dec 2018
syms x y;
f(x) = (2.*x-1).*sin(pi.*x);
y=zeros(1,25);
for i=1:25
y(i)=diff(f(x),i);
end
fun=matlabFunction(y.');
x=-2:0.01:1;
result=fun(x);
maxres = max(result,[],2)
maxres(abs(maxres-0.001)<1e-4) % will return empty because none of the results satisfy the condition

8 Comments

syms x y;
f(x) = (2.*x-1).*sin(pi.*x);
Pn30(x) = taylor(f,'order',30);
terms=children(Pn30);
y(1)=f(x)-terms(1);
for i=2:25
y(i)=y(i-1)-terms(i);
end
fun=matlabFunction(abs(y)');
x=-2:0.01:1;
result=fun(x);
maxres = max(result,[],2)
maxres(abs(maxres-0.001)<1e-4) % but now we have the results satisfy the condition but this return nothing
what's your question ? simply posting the code is meaningless..
in the loop with any i
i can find max y(i) then
compare if max(y(i))<0.001
break loop
madhan ravi
madhan ravi on 24 Dec 2018
Edited: madhan ravi on 24 Dec 2018
Alright try this:
syms x;
a = -2;
b = 1;
f(x) = (2.*x-1).*sin(pi.*x);
Pn10(x) = taylor(f,'order',30);
xMin = a; xMax = b; stepSize = 0.01;
terms = children(Pn10);
y(x) = terms;
x=-2:0.01:1;
Y = cellfun(@max,y(x)) ;
Final_result=[];
for i = 1:numel(Y)
if abs(Y(i)-0.001)<1e-4
break
else
Final_result=vpa(Y(i));
end
end
but this one
solve every Y ( with cellfun)
do u know how to find max in every single step in loop
then i can check result (max<0.001)
Final try rectified the mistakes you can also comapre the results with cellfun it will be the same:
syms x
f(x) = (2.*x-1).*sin(pi.*x);
Pn10(x) = taylor(f,'order',30);
terms = children(Pn10);
y(x) = terms;
x=-2:0.01:1;
Y = y(x);
a=[];
Result=[];
for i = 1:numel(Y)
a(i) = max([Y{i}]);
if a(i) < 0.001
break
else
Result(i)=a(i);
end
end
i did it
thank u so much <3
Anytime :)

Sign in to comment.

More Answers (1)

KSSV
KSSV on 24 Dec 2018
f= @(x) (2.*x-1).*sin(pi.*x);
x=-2:0.01:1;
for i=1:25
y=diff(f(x),i);
if max(y)<0.001
break
end
end

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!