cambiar de matlab a c++
Publicado por angel (1 intervención) el 12/06/2016 02:29:09
quisiera cambiar este codigo a c++ desde la parte donde esta los asteriscos es donde no tengo idea como hacer
gracias c:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
clc
clear all
n=input('Ingrese n:');
h=input('Ingrese el valor de h:');
tol=input('Ingrese la tolerancia:');
N=input('Ingrese el numero de iteraciones:');
%syms h;
for i=1:n
for j=1:n
if i==j
a(i,j)=-2*(1+h^2);
else
if i==j+1 ||i==j-1
a(i,j)=1;
else
a(i,j)=0;
end
end
end
end
%A=inline(a);
for i=1:n
if i==1|| i==n
b(i,1)=1;
else
b(i,1)=0;
end
end
for i=1:n
x(i,1)=0;
end
%disp(a);
%disp(x);
%disp(b);
*****r=b;
aux=r'*r;
v=b;
for k=1:N
z=a*v;
s=aux/(v'*z);
x(:,k+1)=x(:,k)+s*v;
r=r-(s*z);
aux1=r'*r;
if aux1<tol
for i=1:n
fprintf('x(%d)=%8.4f\n',i,x(i,k+1));
end
disp('La sucesion de soluciones aproximadas son');
disp('R=');
disp(x);
disp('Procedimiento terminado con exito');
return;
end
m=aux1/aux;
aux=aux1;
v=r+m*v;
end
if k>=N
disp('Procedimiento terminado sin exito');
disp('Aumente el numero de iteraciones');
end
gracias c:
Valora esta pregunta


0