フィルターのクリア

How to declare variables equal to the number of variables entered by the operator

2 ビュー (過去 30 日間)
Ahsun Ali
Ahsun Ali 2014 年 11 月 6 日
編集済み: Matt J 2014 年 11 月 6 日
I am developing a code for Newton's method for non-linear equations. I intend to take an input of no. of eq's from the user and declare variables equal to the number of equations e.g. No. of eq = 3 then syms x1,x2,x3 or x,y,z. Also, I can't store the equations in a column vector and take the jacobian. I also am unable to evaluate the functions and jacobian at a set of coordinates.I have developed a starting for 2 eq's.
syms x y clear f1 f2
f1=input('Enter First eq:','s');
f2=input('Enter second eq:','s');
X=[0 0];
f1=4*x^2-20*x+1/4*(y^2)+8;
f2=1/2*(x*y^2)+2*x-5*y+8;
j1=jacobian([f1],[x y]);
j2=jacobian([f2],[x y]);
f1=inline(f1,'x','y');
f2=inline(f2,'x','y');
c1=f1(X(1),X(2));
c2=f2(X(1),X(2));
F=[c1 c2]'
j1=inline(j1,'x','y');
j2=inline(j2,'x','y');
c=j1(X(1),X(2));
d=j2(X(1),X(2));
J=[c;d]
Please help me to modify this code for any number of equations entered by the user.

採用された回答

Matt J
Matt J 2014 年 11 月 6 日
編集済み: Matt J 2014 年 11 月 6 日
I intend to take an input of no. of eq's from the user and declare variables equal to the number of equations
No, don't do this. Stick with the approach we've been discussing in your similar post
Instead of having separate f1,f2, etc... develop a single vector-valued symbolic function f. Then you can apply jacobian, gradient, etc... to f with matrix/vector semantics.

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by