Question

In: Physics

Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1...

Write script in Matlab to solve
1. Y=Ax where X is of dimension n by 1 and A is of dimension m by n.
2. C= A*B where A is of dimension m by p and B is dimension of p by n.
So write matlab script to obtain Y and C in above problems.

Solutions

Expert Solution

Since the given question asked for matrix multiplication, I assume that you aren't allowed to use direct '*' operation which can do matrix multiplication directly in MATLAb. So, please find the required MATLAB code below:

clear all; clc; close all;

A=[2 3 5; 4 5 4]; % m*n dimension matrix

x=[4;5;6]; % n*1 dimesion matrix

B=[2 6; 3 6; 4 6]; % n*k dimenion matrix

%% PROBLEM 1

[m,n]=size(A);

[k,l]=size(x);

disp('Solving Problem 1:')

Y=zeros(m,1);

for i=1:m

for j=1:l

for p=1:n

flag=1;

Y(i,j)=Y(i,j)+ A(i,p)*x(p,j);

end

end

end

disp(Y)

%% PROBLEM 2

disp('Solving Problem 2:')

[m,n]=size(A);

[k,l]=size(B);

C=zeros(m,l);

for i=1:m

for j=1:l

for p=1:n

flag=1;

C(i,j)=C(i,j)+ A(i,p)*B(p,j);

end

end

end

disp(C)

========================== SCREENSHOT OF CODE


Related Solutions

using matlab, compute and plot y [n] = x [n]* h [n], where a. x [n]...
using matlab, compute and plot y [n] = x [n]* h [n], where a. x [n] = h [n] = a^n (0 <=n <=40) & a = 0.5 b. x [n] = cos [n]; h [n] = u [n]; n = 0:4:360 c. x [n] = sin [n] ; h [n] = a^n; n:4:360; a = 0.9
Use Matlab and write entier script Problem 1. Using the information above, find y(n) for all...
Use Matlab and write entier script Problem 1. Using the information above, find y(n) for all n between 1:N. y(tn)=mx(tn)+b+r(tn) y=mx+b Plot the points on a graph, without connecting them with a line.   Use a command like: plot( x, y, ‘.r’ ) Now we want to find the “best fit” solution.   As was mentioned before, this was defined in the prior exercise. (You may wish to read this to understand how the algorithm works.)   Use the MATLAB code below. You...
Write your own MATLAB code to solve the system 10 − x + sin(x + y)...
Write your own MATLAB code to solve the system 10 − x + sin(x + y) − 1 = 0 8y − cos2 (z − y) − 1 = 0 12z + sin(z) − 1 = 0 using a residual tolerance of 10^−6 and the initial guess, ~x 0 = [0.1, 0.25, 0.08]^T . Print out the values for x, y and z for each iteration in a table similar to the one you created for the problems of the...
write a Matlab function file to solve system Ax=b by using the output of the function...
write a Matlab function file to solve system Ax=b by using the output of the function lufac2a your function should have inputs f=matrix return from lufac2a, piv=array return by lufac2a and b=right hand side of your system.the only output for your system should be x guideline 1.use the column access for the matrix entries 2. do not create any other matrix in your function-get your data directly from the matrix passed into your function 3.do not use Matlab command designed...
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2...
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2 – K) S(n) – S(n-1) ;   Assume S(1) = 0, S(2) = 1; (a)    Case 1, Assume K = 1 (b)    Case 2, Assume K = 2 (c)     Case 3, Assume K = 4 Plot all of these on the same plot, for N = 1 to 20
2.48. Is it true that {ax + by + cz|x, y, z ∈ Z} = {n...
2.48. Is it true that {ax + by + cz|x, y, z ∈ Z} = {n · gcd(a, b, c)|n ∈ Z}? 2.49. What are all the integer values of e for which the Diophantine equation 18x + 14y + 63z = e has an integer solution. Find a solution for each such e. 2.50. For integers a, b and k > 0, is it true that a | b iff a^k | b^k ?
Using matlab Find x and y that solve the following system: ln(x 2 + y) =...
Using matlab Find x and y that solve the following system: ln(x 2 + y) = 1 − y , xy = − √ x
write a MATLAB script that plots the two functions ( y=(2x^2)-(3x)-4 and y=4sin(2Pix) - 1 )...
write a MATLAB script that plots the two functions ( y=(2x^2)-(3x)-4 and y=4sin(2Pix) - 1 ) in the same figure for x in [-1,3]. Add a title, x-label, y-label, and legend. ( MATLAB code and graph with all descriptions.)
4. The product y = Ax of an m n matrix A times a vector x...
4. The product y = Ax of an m n matrix A times a vector x = (x1; x2; : : : ; xn)T can be computed row-wise as y = [A(1,:)*x; A(2,:)*x; ... ;A(m,:)*x]; that is y(1) = A(1,:)*x y(2) = A(2,:)*x ... y(m) = A(m,:)*x Write a function M-file that takes as input a matrix A and a vector x, and as output gives the product y = Ax by row, as denoted above (Hint: use a for...
Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n'...
Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n' (nxn chart).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT