Solving an implicit equation for y error

I'm trying to solve an implicit equation using the solve function but its giving me a ton of errors
This is the command I'm trying to use:
solve('ln(x)+C==(1/5)ln(5(y/x)^2+4)','y');
The errors I get:
Warning: Support of character vectors that are not valid variable names or define a
number will be removed in a future release. To create symbolic expressions, first create
symbolic variables and then use operations on them.
> In sym>convertExpression (line 1559)
In sym>convertChar (line 1464)
In sym>tomupad (line 1216)
In sym (line 179)
In solve>getEqns (line 405)
In solve (line 225)
Error using symengine
Unexpected 'identifier'.
Error in sym>convertExpression (line 1566)
s = mupadmex({x});
Error in sym>convertChar (line 1464)
s = convertExpression(x);
Error in sym>tomupad (line 1216)
S = convertChar(x);
Error in sym (line 179)
S.s = tomupad(x);
Error in solve>getEqns (line 405)
a = sym(a);
Error in solve (line 225)
[eqns,vars,options] = getEqns(varargin{:});
Thanks to anyone who tries to help!

回答(2 个)

1. Define x and y as syms in advance. So
syms x y
2. Is C a constant or is it also symbolic?
3. No need to put quotes around the expression. Read the warning message.
4. log is the natural log in MATLAB, NOT ln.
5. Multiplication is not achieved if you use no operator. So 5(y/x) is not valid. Use 5*(y/x) instead.
6. Again, if you want to multiply by 1/5, you need to use a * between terms. So (1/5)log would not be legal syntax.
Start there.

4 个评论

Thanks for the help, that fixed a lot of it but this is what I get now:
solve(log(x)+C==(1/5)*log(5*(y/x)^2+4),y);
Warning: The solutions are valid under the following conditions: 5*imag(C) + 5*angle(x)
<= pi & -pi < 5*imag(C) + 5*angle(x);
5*imag(C) + 5*angle(x) <= pi & -pi < 5*imag(C) + 5*angle(x).
To include parameters and conditions in the solution, specify the 'ReturnConditions'
option.
> In solve>warnIfParams (line 507)
In solve (line 356)
Trial>>
So? What is the problem? You got a solution, that is valid only for some values of the parameters. That message tells you the limits under which the solution applies.
Suppose you asked to solve an equation that has no solutions for come values of the parameters? So
sin(x) == C
for real values of x. The problem has no solution for real x if C>1 or C<-1. The warning message that you got was in the same vein, telling you when a solution exists. You can probably ignore it, as long as your parameters make sense.
As Walter points out, there is a solution that is easy to write by hand. But even that is subject to constraints.
Suppose you asked to solve
y/x - 5 == 0
Yes, you COULD just effectively multiply by x, then isolate y by moving the x term to the right hand side.
But what if x were zero? Then then the equation in the original form is simply not valid when x=0, since then we have a 0/0 event. So when x=0, it is not truly valid to claim that
y = 5*x
is the solution, because the pair x=0, y=0 is not a valid solution to the original equation. (I'm surprised that MATLAB does not expressly indicate that as a condition on this last problem.)
I think it was Roger, not me.

请先登录,再进行评论。

You don’t need ’solve’ for solving for y. It can be obtained in the following equation:
y = sqrt(x^7*exp(5*C)/5-4/5*x^2)

Community Treasure Hunt

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

Start Hunting!

Translated by