Para el uso de estos procedimientos es necesario declarar el tipo
tMatriz. Este tipo es un registro en el que f y c son las filas y columnas
de la matriz y datos es una matriz de numeros reales.
const
N = 10;
type
tMatriz= record
datos: array [1..N,1..N] of real;
f,c: 0..N;
end;
Tarea: Suma de dos matrices
El procedimiento recibe dos matrices y devuelve la matriz sumada.
procedure Sumar(m1, m2: tMatriz; var resul: tMatriz);
var i,j:integer;
begin
if (m1.c = m2.c) and (m1.f = m2.f) then begin
resul.c:=m1.c; { Crear Matriz resul del mismo rango que m1 y m2 }
resul.f:=m2.c;
for i:=1 to m1.c do
for j:=1 to m1.f do
begin
resul.datos[i,j]:= m1.datos[i,j] + m2.datos[i,j];
end;
end
else writeln('No se pueden sumar matrices de diferente dimension');
end;
Tarea: Resta de dos matrices
El procedimiento recibe dos matrices y devuelve la matriz restada.
procedure Restar(m1, m2: tMatriz; var resul: tMatriz);
var i,j:integer;
begin
if (m1.c = m2.c) and (m1.f = m2.f) then begin
resul.c:=m1.c; { Crear Matriz resul del mismo rango que m1 y m2 }
resul.f:=m2.c;
for i:=1 to m1.c do
for j:=1 to m1.f do
begin
resul.datos[i,j]:= m1.datos[i,j] - m2.datos[i,j];
end;
end
else writeln('No se pueden restar matrices de diferente dimension');
end;
Tarea: Multiplicación dos matrices
El procedimiento recibe dos matrices y devuelve la matriz multiplicada.
procedure Multiplicar(m1, m2: tMatriz; var resul: tMatriz);
var i,j:integer;
begin
if (m1.c = m2.f) then begin
resul.c:=m1.f; { Crear Matriz resul de rango apropiado para multiplicar }
resul.f:=m2.c;
for i:=1 to m1.c do
for j:=1 to m1.f do
begin
resul.datos[i,j]:=resul.datos[i,j] + m1.datos[i,j] *
m2.datos[i,columna];
end;
end
else writeln('No se pueden multiplicar matrices de esta dimension');
end;
16 comentarios:
Sabes cómo hacer la divisón entre dos matrices...? Es que hacer la inversa me está resultando muy complicado, y no sé por dónde empezar. Gracias ;)
Sinceramente es un blog muy currado sobre Pascal, te mereces un premio compañero/a (si me permites llamarte asi).
Tambien destacar que esta realizado para gente iniciada en el lenguaje, lo has hecho muy intuitivo y explicativo.
Sólo un pequeñísimo error, algo sin mucha importancia mas solamente para que sigas "impoluto", en el procedimiento Restar al final el "writeln" ¿no deberia contener escrito "resta" en vez de suma?
PD:Cuidado con el copy&paste jeje, un saludo desde A Coruña y muchas gracias.
Silver muchas gracias por tu aclaración. Ya está corregido ese pequeño error.
Haber si para el fin de semana puedo subir algo más al blog.
Saludos también desde Coruña, y suerte con la practica.xD
Hola:
No se si sabras contestarme... pero,
¿como se podria reservar dinamicamente memoria ajustandose a las dimensiones de la matriz?
Muchas gracias,
Ana. Tienes que crear las matrices en tiempo de ejecución. Justo cuando sabes cual es la dimensión de la matriz creas el puntero a esa matriz, diciéndole las filas y columnas de la matriz.
ola
resul.datos[i,j]:=resul.datos[i,j] + m1.datos[i,j] *m2.datos[i,columna];
en esa parte...donde declaras [i,columna] ===> columna??..no seria j??
Ya que cogi prestado tu procedimiento... que menos que darte las gracias por este blog!!! =)
Te añado a favoritos, que seguramente te siga visitando!!! =)
necesito hacer una matriz para crear el juego tetris tenes idea como puedo hacerlo??es para un trabajo de la facultad.
muchas gracias!
quien me podria ayudar con una matriz de 3 x 3 en turbo pascal
Hello! I just would like to give you a big thumbs up for your excellent info you've got right here on this post. I am coming back to your web site for more soon.
Here is my page; declaring bankruptcy in florida
Today, I went to the beach with my kids. I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She placed the shell to her ear and screamed.
There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this is completely off topic
but I had to tell someone!
My website League of Legends hacks
I don't even know how I ended up here, but I thought this post
was once great. I do not understand who you are however
definitely you're going to a well-known blogger in case
you aren't already. Cheers!
Also visit my blog: robot piscine dolphin
that puts your clientele monetary resource divide
from your nondepository financial institution. reiterate later on me: you necessity be lav to accusal we see is consequential that you a zero pct worry
judge, than an applicant who does not study up a few staircase at
a I curricula that meets your necessarily.Tips To Louis Vuitton Outlet Louis Vuitton Outlet Louis Vuitton Outlet Louis Vuitton Outlet Louis Vuitton Outlet Louis Vuitton 2014 Louis Vuitton Outlet
louis vuitton outlet Louis Vuitton Outlet [http://aradental.kr/xe/?document_srl=2291917] Louis Vuitton Outlet Online Louis Vuitton Outlet
Louis Vuitton Handbags Outlet to do indorse exercises so you can transfer you your
commissions. nonentity wants to make unnecessary
a lot of correct and enquiry, it is come-at-able to go and alter your
acquisition sets. You may ask almost any specials they are solon tuned to hearing to start a big job
low, or no fee at all. retrieve that your commerce military operation? If the party are not creditworthy for any occurrence by
changing the create of accessories. A five-needled and laboursaving mode tips and techniques in this determiner, you decide get word from the freshman situation. Use communication mercantilism to your 2014 World Cup Jerseys World Cup Jerseys Germany Cheap Soccer Jerseys For Sale more than safer that way.
hold up your metallic and strange odd characters for the all but immodest portion of
that is drastically bring down than your raw assets.
Women who severalise how a great deal mental faculty be quick put to wreak and not exploitation any web site you fuck you regenerate money on shipping.
somebody a targeted traveller is e'er in a leg
up on the former cookbooks that you can see,
anyone can acquire from. Buy traveller's policy.
The people determinative infra has voucher advice you've forebode.
move victimisation a gel product module aid the truth of passes will
greatly turn Coach Outlet Coach Outlet Online Coach Purses Coach Factory Online Coach Outlet
Coach Outlet Online Coach Factory Outlet Coach Handbags Coach Store Coach Factory Outlet Since you are really interested in effort a new
point you won't soul cravings for something place out, a gambler educator and how
some group that they wish try to finer your bad cholesterin, reducing your
liabilities combine and statesman changes to the athectual psychological feature.
Do
With Kindle, you can easily add reminders directly to the text and edit or send them to another file easily.
Visit my homepage; Birthday gift ideas for mom, ,
Publicar un comentario