Solving Equation
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm trying to solve a equation, and I'm having some issues...
syms Xell Xelr Xerl Xerr s q; s = solve('(Xell-Xelr)/(Xerl-Xerr) = -(((s-1)*(s-(1+2/q)))/((s+1)*(s+(1+2/q))))', s);
How do i use the results and enter values in for the syms (i.e. Xell Xelr Xerl Xerr q) to solve for s?
Thanks! Mark
1 Kommentar
Akzeptierte Antwort
Oleg Komarov
am 11 Feb. 2011
Not sure the best method, convert to function handles:
syms Xell Xelr Xerl Xerr s q;
s = solve('(Xell-Xelr)/(Xerl-Xerr) = -(((s-1)*(s-(1+2/q)))/((s+1)*(s+(1+2/q))))', s)
s1 = str2func(['@(Xell, Xelr, Xerl, Xerr, q)' char(s(1))]);
s2 = str2func(['@(Xell, Xelr, Xerl, Xerr, q)' char(s(2))]);
% Evaluate at the desired values
s1(1,1,3,1,2)
s2(1,1,4,1,2)
Oleg
0 Kommentare
Weitere Antworten (3)
Mark
am 11 Feb. 2011
1 Kommentar
Oleg Komarov
am 11 Feb. 2011
I'm running your part of the code first and then my part of the code and don't get the difference you say.
Clear all and run again the script, which I'll complete with your part.
Mark
am 11 Feb. 2011
1 Kommentar
Oleg Komarov
am 11 Feb. 2011
How can you get sneg = ... if you're solving s = solve...? Where does sneg come from? (btw I corrected again my original post)
Walter Roberson
am 11 Feb. 2011
You are going to get two solutions returned. You need to take that in to account. You are effectively solving a quadratic, so two solutions.
for K=1:length(s); funcs{K} = matlabFunction(s(K)); end
Now funcs{K} will be a function handle that you can pass the values in to and get solutions for s. Please see the matlabFunction documentation for information as to what parameter order the generated functions will expect.
0 Kommentare
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!