Inputting equation for creating matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Sunand Agarwal
am 14 Dez. 2020
Hello,
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!