Trying to solve an equation with an unknown on each side

2 次查看(过去 30 天)
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