i need help on solve function

조회 수: 2 (최근 30일)
MD.MASHRAVI SHAMS
MD.MASHRAVI SHAMS 2020년 3월 31일
답변: Deepak 2024년 11월 14일
hi i have a code for
clc
syms x y z
format long
x= linspace(200,1400,10000);
y= linspace(100,900,10000);
z= linspace(7380,8046,10000);
a=588545.909;
b=10167.688;
c=150;
eqn = a.*x+b.*y+c.*z == 189900000;
s = solve(eqn,x,y,z)
but this code is giving error
Error using sym.getEqnsVars>checkVariables (line 92)
Second argument must be a vector of symbolic variables.
Error in sym.getEqnsVars (line 54)
checkVariables(vars);
Error in solve>getEqns (line 429)
[eqns, vars] = sym.getEqnsVars(argv{:});
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
Error in Untitled (line 11)
s = solve(eqn,x,y,z)

답변 (1개)

Deepak
Deepak 2024년 11월 14일
The error occurs because the solve function is expecting symbolic variables as input, but numeric values are assigned to x, y, and z using linspace. This reassignment overrides the symbolic variables initially declared with syms. To resolve this issue, ensure that x, y, and z remain symbolic when passed to the solve function.
Remove the “linspace” statements to ensure parameters “x”, “y”, and “z” remains symbolic.
Here is the MATLAB code with the required changes:
clc;
syms x y z;
format long;
% Define the symbolic equation
a = 588545.909;
b = 10167.688;
c = 150;
eqn = a*x + b*y + c*z == 189900000;
% Solve the equation for the symbolic variables
s = solve(eqn, [x, y, z]);
disp(s);
For more information on the functions used refer to the following documentation:
I hope this will help resolving the issue.

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by