MATLAB 1) Write a function that will accept a file name and two words. The funct
ID: 3691386 • Letter: M
Question
MATLAB 1) Write a function that will accept a file name and two words. The function will open the file and read it one line at a time. If the line contains the first word passed to the function, replace that word with the second word passed to the function. This is essentially a find and replace function. All occurrences of the first word should be replaced. Assume capitalized words are different from non-capitalized words. For example, if you are replacing the word ‘see’ don’t replace ‘See’. The function should open a new file with the same name but with ‘New_’ add to the beginning of the file name. You can use the EMF.txt file in Canvas. If you do, the new file will be named New_EMF.txt. Write the replaced text to the new file.
2) Write a function that will accept a matrix and return a matrix. The function should take the passed matrix and using Gauss Elimination put zeros in the first column of the matrix. The first step is to put the row with the largest absolute value in the first row by swapping using two functions you wrote in a previous homework. Then calculate the factor necessary to multiply the first row by so that when it is added to the second row, the element in row 2 column 1 becomes zero. Use your linear combination function to accomplish this task. Then move down to the next row. Keep looping through the rows until all the elements in column 1, except row 1, are zero.
Explanation / Answer
1)
Please follow the code and comments for the description of the code :
CODE :
function [pi] = GE(Q)
function [x] = GaussianEliminate(A, b)
%work out the number of equations
N = length(b)
%Gaussian elimination
for column=1:(N-1)
%work on all the rows below the diagonal element
for row = (column+1):N
%work out the value of d
d = A(row,column)/A(column,column);
%do the row operation
A(row,:) = A(row,:)-d*A(column,:)
b(row) = b(row)-d*b(column)
end%loop through rows
end %loop through columns
%back substitution
for row=N:-1:1
x(row) = b(row);
for i=(row+1):N
x(row) = x(row)-A(row,i)*x(i);
end
x(row) = x(row)/A(row,row);
end
%return the answer
x = x’;
return
2)
Please follow the code and comments for the description of the code :
CODE :
fid = fopen('input.txt','r');
f=fread(fid,'*char')';
fclose(fid);
f = regexprep(f,'<s> ','');
f = regexprep(f,' </s>',' .');
fid = fopen('output.txt','w');
fprintf(fid,'%s',f);
fclose(fid);
I just took the samples for the replacement in real time you can change that accordingly.
Hope this is helpful
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.