Trying to solve an equation with an unknown on each side
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Star Strider
am 29 Okt. 2015
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)));
Antworten (1)
Star Strider
am 28 Okt. 2015
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 Kommentare
Star Strider
am 28 Okt. 2015
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.)
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!