kann mir bitte einer mit Matlab folgende Aufgabe lösen?
[Bild im Archiv nicht verfügbar]
Vom Duplikat:
Titel: Erzeugen Sie mit Hilfe von MatLab eine gemeinsame Darstellung der Funktion f(x) = 1/(1 - x)
Stichworte: taylorpolynom,entwicklungspunkt
kann mir bitte einer diese Aufgabe mit MatLab programmieren?
Ich brauche den Quellcode. Die Zeichnung werde ich dann selber erzeugen lassen.
[Bild im Archiv nicht verfügbar]
% Berechnung der Taylorreihe für die Funktion 1/(1-x)
x = -2:0.1:2;
y = 1./(1-x);
N = 30;
z = 0;
for k=0:N
z = z + x.^k;
end
plot(x,y,'r',x,z,'b','LineWidth',2);
axis([-2 2 -10 10])
grid;
Ich muss diese Aufgabe auch machen. Wir sollen das mit der Matlab-Funktion taylor() machen.
In der Aufgabenstellung steht ja, dass man eine gemeinsame Darstellung verwenden soll. Wie mache ich das? Was bedeuten die Parameter in den Klammern von taylor(f,7,x,0.5)?
Bei mir kommt foldenge Fehlermeldung, wenn ich es ausführe:
Error using sym/taylor (line 99)
The value of 'x' is invalid. It must satisfy the function: @(x)isvector(x)&&isAllVars(x).
Error in Untitled2 (line 3)
taylor(f,7,x,0.5);
Bei mir klappt dieser Code
% Berechnung der Taylorreihe für die Funktion 1/(1-x)
syms x;
f = 1./(1-x);
t10 = taylor(f,10,x);
t3 = taylor(f,3,x);
xd = -2:0.001:2;
yd = subs(f,x,xd);
ezplot(t10, [-2,2]); hold on;
ezplot(t3, [-2,2]); hold on;
plot(xd, yd, 'r-');
ylim([-10.0 10.0]);
ylim([-2.0 2.0]);
grid;
title('Taylor approximation vs. actual function');
legend('Taylor','T10','T3');
Ok, ich habe das korrigert. Habe es so gemacht:
t10 = taylor(f, x, 10);
t3 = taylor(f, x, 3);
Das x muss an zweiter Stelle stehen.
Ich bekomme jetzt aber diese Fehlermeldungen:
Error using symengine (line 59)
Division by zero.
Error in sym/subs>mupadsubs (line 139)
G = mupadmex('symobj::fullsubs',F.s,X2,Y2);
Error in sym/subs (line 124)
G = mupadsubs(F,X,Y);
Error in Untitled2 (line 6)
yd = subs(f, x, xd);
Irgendwie scheint er mit der Zeile xd = -2:0.001:2; nicht klar zu kommen. Bin mir aber nicht sicher. Was soll ich tun :(
Hier ist der Code:
syms x;
f = 1./(1-x);
t5 = taylor(f, x, 5);
t10 = taylor(f, x, 10);
t25 = taylor(f, x, 25);
t50 = taylor(f, x, 50);
xd = -2:0.001:2;
yd = subs(f, x, xd);
ezplot(t5, [-2,2]); hold on;
ezplot(t10, [-2,2]); hold on;
ezplot(t25, [-2,2]); hold on;
ezplot(t50, [-2,2]); hold on;
plot(xd, yd, 'r-');
ylim([-10.0 10.0]);
ylim([-2.0 2.0]);
grid;
title('Taylor approximation vs. actual function');
legend('Taylor','T5','T10','T25','T50');