필터 지우기
필터 지우기

Trying to solve an equation with an unknown on each side

조회 수: 2 (최근 30일)
Afrdev
Afrdev 2015년 10월 28일
댓글: Star Strider 2015년 10월 29일
Really enjoying using matlab for the first time, finding it quite intuitive!
I am trying to solve an equation that has me scratching my head. Im sure the code is sloppy but basically I would like to solve the following equation ;
Im looking to get a value for Th, all other values are already known. I have written it in this way as I was trying to utilize the 'solve' function, e.g.
solve(RAM, Th)
Which returns
Error using solve (line 267) Specify a variable for which you solve.
Error in Script 1 (line 47) solve(RAM, Th)
Apologies if im going around this the totally wrong way, looking forward to hearing back from someone!
Thanks, J
  댓글 수: 1
Star Strider
Star Strider 2015년 10월 29일
Context: The now-deleted code is the RAM function in my Answer. It was originally a Symbolic Math Toolbox assignment as:
RAM = (x+y)*Th == (m*(a*9.81)*(h*cos(Th)))+((m*9.81)*(h*sin(Th)));

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

답변 (1개)

Star Strider
Star Strider 2015년 10월 28일
You can’t get there from here because ‘Th’ is an argument to the trigonometric functions. There are likely infinite solutions.
Rearrange the equation, then use fzero to find the value of ‘Th’. Graph it first, to see where the approximate zero-crossings of the function are, then use those approximate start values to estimate the more precise values with fzero:
[x, y, m, a, h] = deal(2,3,5,7,11); % Assign Constants
RAM = @(Th) (x+y)*Th - (m*(a*9.81)*(h*cos(Th)))+((m*9.81)*(h*sin(Th))); % Anonymous Function
Th = fzero(RAM, 1); % ‘Th’ Near ‘1’
Th =
1.4270
  댓글 수: 3
Afrdev
Afrdev 2015년 10월 28일
I'll have to check but using your help i'm pretty close to an answer I expected. Many thanks for you help, you truly are a star!
Star Strider
Star Strider 2015년 10월 28일
My pleasure!
The ‘Th’ angle by any other name would be as analytically incalculable. The reason is that they are not periodic, but vary because the ‘baseline’ of the function is not flat. This calculates and plots a few of them from -50 to +50:
[x, y, m, a, h] = deal(2,3,5,7,11); % Assign Constants
RAM = @(Th) (x+y)*Th - (m*(a*9.81)*(h*cos(Th)))+((m*9.81)*(h*sin(Th))); % Anonymous Function
a = linspace(-50, 50, 250);
RAMv = RAM(a); % Calculate ‘RAM’ For A Vector Of Angles
zxc = find((RAMv.*circshift(RAMv, [0 -1]))<=0); % Approximate Zero-Crossing Indices
for k1 = 1:length(zxc)
Th(k1) = fzero(RAM,a(zxc(k1))); % Precise Zero Crossings
end
figure(1)
plot(a, RAMv)
hold on
plot(Th, zeros(size(Th)), 'r+')
hold off
grid
I also correct what I said about there being an infinite number of values for ‘Th’. It is clear from the plot that at some point it will fall completely below the x-axis for negative angles and rise completely above it for positive angles, so there will be no further zero-crossings beyond those limits, giving a finite number of solutions. (I should have plotted it first.)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by