zero(s) of a nonlinear implicit function

조회 수: 3 (최근 30일)
Ali Kiral
Ali Kiral 2025년 3월 15일
편집: Ali Kiral 2025년 5월 30일
I want to find the roots of an implicit function whose dependant variable is impossible to isolate. In particular, I want to find an array of outputs for a given array of inputs. That function is
1.5786+3*cosd(theta4-1.0714*cosd(theta2)-cosd(theta4-theta2)=0
Here, theta2 is the input and theta4 is the output. A function m-file:
function theta4 = fourbar(theta2)
theta2=0:0.5:360;
for i =1:length(theta2)
1.5786+3*cosd(theta4(i))-1.0714*cosd(theta2(i))-cosd(theta4(i)-theta2(i))
end
In the command prompt with an initial guess of 0.01 does not work:
fsolve(@fourbar,0.01)
How can I pass the elements of theta2 to the function 'fourbar' and then solve for theta4 in another array?

채택된 답변

Walter Roberson
Walter Roberson 2025년 3월 16일
In particular, I want to find a array of outputs for a given array of inputs.
That is not possible using fsolve() -- not unless you use a for loop or arrayfun to process one at a time.
fsolve() is strictly for a single output given a vector of input parameters.
  댓글 수: 2
Walter Roberson
Walter Roberson 2025년 3월 16일
syms theta2 theta4 real
C1 = sym(1.0714);
eqn = sym(pi)/2+3*cosd(theta4)-C1*cosd(theta2)-cosd(theta4-theta2)
eqn = 
for K = 1 : 50
result(K) = vpasolve(eqn, [theta2, theta4], [rand()*360; randn()]);
end
T2 = [result.theta2];
T4 = [result.theta4];
mask = T2 >= 0 & T2 <= 360;
T2 = T2(mask);
T4 = T4(mask);
sortrows([T2; T4].')
ans = 
Walter Roberson
Walter Roberson 2025년 3월 16일
syms theta4 real
theta2 = sym(339.85);
C1 = sym(1.0714);
eqn = sym(pi)/2+3*cosd(theta4)-C1*cosd(theta2)-cosd(theta4-theta2)
eqn = 
for K = 1 : 50
result(K) = vpasolve(eqn, [theta4], [randn()]);
end
T4 = [result];
sortrows(T4.')
ans = 

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by