Sie sind auf Seite 1von 4

% finding mth power of n*m mtrix

function [B]=matpow(n)
disp('enter elements for square matrix');
for i=1:n
for j=1:n
A(i,j)=input('');
end
end
m=input(nter the power');
if(m<0)
disp('error, negative argument');
else
B=A^m
end
filename matpow.m
-------------------------------------------exercise 2(point 6)
for i=1:100
a=F(i,1);
for j=1:3
if F(i,j)>a
max(i)=j;
a=A(i,j);
end
end
end
maxindex=max
-----------------------------------------functin zdot=vib(t,z)
k/m=input('enter k/m value');
zdot=[ z(2); -(k/m)*(z(1)]
file viv.m
--------------------------------tspan [0 20]; z0=[0;0]
[t,z]=ode 23('vib', tspan, z0);
x=z(:,1);
plot(t,x)
xlabel('t'), ylabel('displacement')
title('time vs displacement')
file vib1.m
---------------------------------------functin zdot=vib2(t,z)
m=input('enter mass');
c=input('enter damping const');
k=input('enter stiffness of spring');
zdot=[ z(2); -(c/m)*(z(2) -(k/m)*(z(1)]

file vib2.m
-------------------------------------------%program to solve free vibration of single degree freedom system with damping
tspan [0 20]; z0=[0;0]
[t,z]=ode 23('vib2', tspan, z0);
x=z(:,1);
plot(t,x)
xlabel('time')
ylabel('displacement')
title('time vs displacement')
file vib3.m
--------------------------------------------------#include<stdio.h>
main()
{
FILE *f1 , *f2 , *f3;
char A[50][50]="mat1.dx";
char B[50][50]="mat2.dx";
scanf("%d",& x);
printf("enter integer for %d size square matrix",n);
if(f1=fopen("mat1,""w");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
fscanf(stdin, "%d", & A[i][j]);
fprintf(f1, "%d", & A[i][j]);
}
}
else
{
f1=fopen("mat1","a");
fprintf(f1,"appending to the end of the file");
}
fclose(f1);
f(f2=fopen("mat2","r")==null)
{
f2=fopen("mat2","w");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
B[i][j]= A[i][j]);
fscanf(stdin, "%d", & B[i][j]);
fprintf(f2, "%d", & B[i][j]);
}
}

else
{
f2=fopen("mat2","a");
fprintf(f2,"appending to the end of the file");
}
fclose(f2);
printf("transpose of the matrix is",n);
if(f2=fopen("mat2,""r")==null)
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
fprintf(f2, "%d", & B[i][j]);
}
}

Das könnte Ihnen auch gefallen