フィルターのクリア

How to solve unknown number of equations

2 ビュー (過去 30 日間)
Yagna V
Yagna V 2020 年 1 月 19 日
回答済み: Guru Mohanty 2020 年 1 月 25 日
Let say I do not know the number of equation to be formed.
Let say I need n, the number of equations,
where n may vary from solving each time.
for i=1:n
syms vi vi+1 v-1
eqn i = (vi+1)^2+(vi-1)^2==20
end
So I get my n number of equation. However that won't work in matlab. Kindly suggest how to do the same.

回答 (2 件)

Guru Mohanty
Guru Mohanty 2020 年 1 月 22 日
Hi, I understand you are trying to create number of equations. You can do this using syms. Here is a sample code.
clc;
clear all;
n=input("Enter Number of Equations to be formed: ");
syms v [1,n]
for i=1:n
eqn(i) = (v(i)+1)^2+(v(i)-1)^2==20;
disp(eqn(i));
end
  1 件のコメント
Yagna V
Yagna V 2020 年 1 月 22 日
thank you very much!
could you help me in solving the same equations with unknown variables

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


Guru Mohanty
Guru Mohanty 2020 年 1 月 25 日
Hi Yagna, You can solve the same equations using solve function in MATLAB.
Here is a sample code for it.
clc;
clear all;
% Forming Equation
n=2;
syms v [1,n]
for i=1:n
eq(i) = (v(i)+1)^2+(v(i)-1)^2==20;
disp(eq(i));
end
% Solving Equation
[v1_sol,v2_sol]= solve(eq,v);
disp(v1_sol);
disp(v2_sol);

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by