Iteration durchführen anhand einer For Schleife
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hallo,
ich möchte die unten stehende Funktion numerisch untersuchen und möchte das ganze mit einem Iterationsverfahren aneghen zur Bestimmung des Fixpunktes. Nun gibt es zwei erstellte Funktionen, die mit dem Wert 1.5 anfangen sollen und beobachtet werden soll, wie sich die Werte bezüglich des Fixpunktes verhalten. Nachdem ich den Code laufen lasse, kommt folgende Meldung:
"Unable to perform assignment because the left and right sides have a different number of elements.
Error in Num (line 24)
x(i+1) = nthroot(2*x+0.5*sin(x),3); "
Könnt Ihr bitte helfen?
%alle Variablen, Fenster und Command Window schließen
clear all;
close all;
clc;
%Funktion F(x) und ihre positive Nullstelle
fun = @(x)-x.^3+2*x+0.5*sin(x);
x0 = 2;
fzero(fun,x0)
x=-3:0.1:3;
y=-x.^3+2*x+0.5*sin(x);
a=x-x;
plot(x,a)
hold on;
plot(x,y)
xlabel('x'); ylabel('y');
hold on;
plot(fzero(fun,x0),0,'o')
hold on;
legend('x-Achse' , 'F(x)','Nullstelle')
%Startwert
x(1)=1.51
%erste Umformung
for i = 1 : 15
x(i+1) = nthroot(2*x+0.5*sin(x),3);
end
k_1 = x(i)
%zweite Umformung
for i = 1 : 20
x(i+1) = ((x.^3-0.5*sin(x))/2);
end
k_2 = x(i)
2 comentarios
madhan ravi
el 16 de Nov. de 2023
Die bestehende Fehlermeldung tritt aufgrund der Dimension der Variable x auf. Du versuchst, einen Wert mit mehreren Werten zu belegen. Leider funktioniert das nicht mit einem numerischen Array. Daher muss man immer den Index in der For-Schleife wie in der gegebenen Antwort verwenden.
Respuestas (1)
Dyuman Joshi
el 16 de Nov. de 2023
Movida: Dyuman Joshi
el 16 de Nov. de 2023
%Funktion F(x) und ihre positive Nullstelle
fun = @(x)-x.^3+2*x+0.5*sin(x);
x0 = 2;
y0 = fzero(fun,x0)
x=-3:0.1:3;
y=-x.^3+2*x+0.5*sin(x);
a=x-x;
plot(x,a)
hold on;
plot(x,y)
xlabel('x'); ylabel('y');
hold on;
plot(y0,0,'o')
hold on;
legend('x-Achse' , 'F(x)','Nullstelle')
%Startwert
x1=1.51;
%erste Umformung
for i = 1 : 15
x1(i+1) = nthroot(2*x1(i)+0.5*sin(x1(i)),3);
end
x1
k_1 = x1(end)
x2 = 1.51;
%zweite Umformung
for i = 1 : 20
x2(i+1) = ((x2(i).^3-0.5*sin(x2(i)))/2);
end
x2
k_2 = x2(end)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!