How do I create a function that solves systems of linear equations of N size?

1 ビュー (過去 30 日間)
Tobias Rubensson
Tobias Rubensson 2020 年 12 月 21 日
コメント済み: Ameer Hamza 2020 年 12 月 21 日
function [findV] = size(N)
A=2*diag(ones(N,1))-diag(ones(N-1,1),1)-diag(ones(N-1,1),-1);
F=[1:N]';
findV =A\F;
end
Is it possible to make a function like this? That takes in a variable N and calculates V from A and F.

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 12 月 21 日
"Is it possible to make a function like this?"
Yes. Just name it something else, since size() is a built-in function.
x = mySize(10)
function [findV] = mySize(N)
A=2*diag(ones(N,1))-diag(ones(N-1,1),1)-diag(ones(N-1,1),-1);
F=[1:N]';
findV =A\F;
end
Result
>> x
x =
20.0000
39.0000
56.0000
70.0000
80.0000
85.0000
84.0000
76.0000
60.0000
35.0000
  2 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 12 月 21 日
I am glad to be of help!!!

サインインしてコメントする。

カテゴリ

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by