[Error using char] How do I solve a transcendental equation for given variables?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
This is my code which enabled a graph to be plotted.
s = 'F/(11*((0.8*10^-3)^2)*2.41*10^9)= sin(x)*((cos (18.97)/cos (x))-1)^1.5';
ezplot(s , [5 10 15 20])
This is the code which gave the following error.
*Error using char Complex values cannot be converted to chars
Error in solve>getEqns (line 245) vc = char(v);
Error in solve (line 141) [eqns,vars,options] = getEqns(varargin{:});*
//Defining variables
a =5;
b=13;
c=1*10^-3;
d=0.57*10^-3;
e = 0.57*10^-3;
f=0.02*10^-3;
g = d/c+e/c-1;
h = acos(1 - f/(2*g*c));
i = 6*(10^6)*g^2+3*(10^6)*g*6894.75729;
//Transcendental function
k= '(a/(b*(c^2)*i) = (sin(j)*((cos(h))/(cos(j))-1)^1.5)';
ezplot(k, [5 10 15 20]);
The concern I have is the error only appears when I change the value within the function into a defined variable (e.g a,b,c)
What am I doing wrong and how do I correct this?
0 Commenti
Risposta accettata
Walter Roberson
il 21 Feb 2013
When you pass a string, values you have set in the workspace are not used. So the "i" you defined as a real value will not be paid attention to and instead "i" will have its default meaning as the imaginary constant, sqrt(-1)
Try
k= @(j) (a/(b*(c^2)*i) - (sin(j)*((cos(h))/(cos(j))-1)^1.5);
13 Commenti
Walter Roberson
il 23 Feb 2013
Is there a point in plotting it over a range of F? The result is linear in F, so the other plots would just be multiples of the plot for F = 1.
If b is known, then it should not be a parameter to s,
s = @(F,x) F ./ (b .* ((0.8*10^-3)^2)*2.41*10^9) - sin(x) .* ((cos (18.97) ./ cos (x))-1).^1.5
However when I go back to your original equations, the cos(18.97) has no apparent foundation. That term seems to be from cos(h) where h is acos() of an expression, and that expression does not work out to 18.97 (it works out to 14/13). The original equations also have no "F" so it is a mystery where that appears.
The original equations down to "k" define an equation in "x" that is dependent upon a number of parameters, including the "b=13". If you use that "b=13" then the equation becomes an equation in one variable, one that involves the solution to quintics (5th order polynomials). There are two branches of solution, one of which appears to be the exact negative of the other.
If, as suggested by your later expression, you allow "b" to be a second variable, then Yes, you get a (pair of) quintics in two variables, which you can thus plot over a range of "b" values. As noted the two quintics are exact negatives, and it also turns out that "b" only appears in them as "b^2" so the results are symmetric around the "b" axis; you can thus plot against non-negative "b" to get a full idea of the shape. If you go out to even moderate "x" such as x=35 then you start getting notable artifacts of round-off, so it is better to do this work in higher precision such as the symbolic toolbox with the number of digits turned up.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!