Inputting equation for creating matrix

조회 수: 11 (최근 30일)
Eray Bozoglu
Eray Bozoglu 2020년 12월 9일
답변: Sunand Agarwal 2020년 12월 14일
Good evening
I can have a matrix with writing A(x,y)=..equation.. However, i have different equation and instead of changing script everytime i want to create script which can form a matrix from inputted equation. Although i tried some different codes, seems like i am walking away from what i want. Anyone can help me? You can see the current code below. Thanks
n=input('please enter n=')
eq1=input('please enter equation for creating A matrix=', 's')
A = zeros(n);
B =(n);
for y=1:n
B(y)=y;
for x=1:n
A(x,y)=inline(eq1,x,y);
end
end
A %matrix A
B %matrix B

답변 (1개)

Sunand Agarwal
Sunand Agarwal 2020년 12월 14일
Hello,
You might want to use MATLAB functions to achieve your objective.
For example,
function [A, B] = create_matrix(n, eq)
%your code
end
You can then create different matrices by passing different equations to the function.
Hope this helps.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by