Metodo Newton
Publicado por Chema (3 intervenciones) el 02/05/2017 17:52:16
Estoy haciendo el metodo de Newton:
Pero me da este error:
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in strcat (line 94)
s(pos:pos+len-1) = str;
Error in Newton (line 6)
df = strcat('diff(',F,')');
Error in P5_4 (line 13)
Newton(f,2,10^-3)
No entiendo muy bien lo de A = B
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function [ X ] = Newton( F,x0,e )
i = 1;
Ea = e;
z(1) = x0;
syms x;
df = strcat('diff(',F,')');
ddf = strcat('diff(',F,',2)');
df = eval(df);
ddf = eval(ddf);
while Ea >= e
x = z(i);
X(i,1) = i;
X(i,2) = x;
f = eval(F);
ff = eval(df);
fff = eval(ddf);
z(i+1) = x -((f * ff)/(ff^2 - (f*fff)));
if i > 1
Ea = abs((z(i) - z(i-1))/z(i))*100;
X(i,3) = Ea;
if Ea < e
break;
end
else
X(i,3) = 100;
end
i = i + 1;
end
end
1
2
3
4
5
syms x;
f = x^2 -sin(x) -0.5;
% funcion f | a1 = 2 y a1 = −1| tolerancia 10^-3 | error = 10^-3 | n = 4
Newton(f,2,10^-3)
Pero me da este error:
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in strcat (line 94)
s(pos:pos+len-1) = str;
Error in Newton (line 6)
df = strcat('diff(',F,')');
Error in P5_4 (line 13)
Newton(f,2,10^-3)
No entiendo muy bien lo de A = B
Valora esta pregunta


0