필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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 CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by