1 view (last 30 days)

Hello,

I don't use matlab much and my coding skills aren't too good. Any help would be appreciated. I am trying to solve the equation:

0.001 * 18 * ( -x/2 + x^(1/3) ) = -log(1-x) + x + 0.4*x^2

I tried:

syms x

eqn = 0.001 * 18 * ( -x/2 + x^(1/3) ) == -log(1-x) + x + 0.4*x^2 ;

S = solve(eqn,x)

But it gave me the trivial solution of x=0, which isn't what I am looking for, so I tried a plotting based code:

x= linspace(0,100);

y = -log(1-x) + x + 0.4*x^2;

q = 0.001 * 18 * ( -x/2 + x^(1/3) );

plot(y,x,q,x)

But that is also giving me issues. I think it may have something to do with using the dot operator (.) to define y and q as an array of values corresponing to the array of values of x, rather than a single value, because I remember that giving me trouble in the past, but I tried a few versions and I am still using it incorrectly. Please help.

Star Strider
on 18 Nov 2020

Since you wnat a numeric result, use vpasolve instead, wither with an initial value (if you have an idea of what that is) or a random value (that I use here):

syms x

eqn = 0.001 * 18 * ( -x/2 + x^(1/3) ) == -log(1-x) + x + 0.4*x^2 ;

S = vpasolve(eqn,x, 'Random',1)

In different runs it returned:

0.00084760100256718346991013215880274 - 5.4840170403140472394650157772261e-34i

0.00084760100256718346991013215880166

0.00084760100256718346991013215880125 + 2.629191905223913240754608540514e-34i

Jon
on 18 Nov 2020

I don't have the symbolic toolbox, but you can also solve this type of problem using fzero

You need to write a little function that will equal zero at a solution to your equation, so put all of the terms on one side so that you have f(x) = 0, so make a script which includes a function definition such as shown below. You could also do this a little more compactly using anonymous functions.

Note that you are going to have problems due to the fact that log(1-x) is complex for x>1 and x^(1/3) is complex for x<0. I got around this in the example below by just taking the real part, but I don't know if this is what you are looking for

%

x0 = 3; % I put this arbitrarily you may have a better guess

x = fzero(@myfunc,x0)

function fval = myfunc(x)

% x - possible solution

%

fval = real(.001 * 18 * ( -x/2 + x^(1/3) ) -(-log(1-x) + x + 0.4*x^2))

end

Jon
on 18 Nov 2020

Jon
on 18 Nov 2020

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

Start Hunting!
## 0 Comments

Sign in to comment.