Hello everyone,
i have to write function in script file with a scala z and M matrix as inputs. M will be 20x20 random matrix, and z will has 100 distinct values between [-2 2] interval, and also i need plot this function.
M=randn(20,20);
n = 100;
R = [-2 2];
z = rand(n,1)*range(R)+min(R);
I=eye(20,20);
function out1 = f(z,M)
A=(M-z*I);
out1=det(A);
end
but i can not call function and get output values, please who can help me?

댓글 수: 2

> i can not call function and get output values
You can call the function but you get errors. First, I is not defined in the function. Should that value be passed into the function? Then you have another problem. Z is 100x1 vector and I is 20*20 matrix, how were you planning on multiplying those variables? They do not conforum to requirements for matrix multiplication, they do not have the same number of elements for element-wise multiplication, and they do not conform the requirements of implicit expansion.
actually exact question is here:
Write a function in a scirpt file that has two inputs: a scalar z and the matrix M, hence y =f(z,M). The function output y is the determinant of the matrix M -zI, where I is an identity matrixof the same size as M:
f(z,M)=|M-zI|
where |.| is the determinant of a matrix.
In a script file, generate a 20x20 matrix M of your choice(but not a zeros, ones or identity matrix) and evaluate the function f at 100 distinct z values between (-2,2) and M matrix.Plot the function values with a dashed red line across the z values. Name the the x axis with "z values" and y axis with "Function values".
and last situation of my code is this:
function out1 = f(z,M)
M=randn(20,20);
n = 100;
R = [-2 2];
z = rand(n,1)*range(R)+min(R);
I=eye(20,20);
A=(M-z.*I);
out1 = det(A);
load mydata;
end

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2021년 1월 20일
편집: Adam Danz 2021년 1월 20일

0 개 추천

> Write a function in a scirpt file that has two inputs: a scalar z and the matrix M, hence y =f(z,M)
Hint: z is not scalar in your code. Scalar variables have 1 values of size 1x1.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2021년 1월 20일

편집:

2021년 1월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by