Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem solving equation

Subject: Problem solving equation

From: Gianluca

Date: 9 Nov, 2012 19:57:14

Message: 1 of 3

Hi,

I am new in matlab and I need some help to solve a simple equation. This is my code:

clc
clear all

C=3.208; % Jacobi constant
M1= 5.9736e24; % Mass of Earth in kg
M2= 7.3477e22; % Mass of Moon in kg
mu=M2/(M1+M2);

for x=-4e6:10000:4e6;
    i=1:1:length(x);
    
    syms x y

    y(i)=solve(x(i).^2+y(i).^2+2*(1-mu)./sqrt((x(i)+mu).^2 + y(i).^2)+2*mu./sqrt((x(i)-1+mu).^2+y(i).^2)-C, y(i)); % solve the equation
    % for the y variable.
end

It's a very simple code but Matlab gives me the message:

Warning: Explicit solution could not be found.
> In solve at 83

It doesn't gime an error; just this message. I don't know where I am wrong. Thanks a lot to anyone who will help me.

Regards

Gian

Subject: Problem solving equation

From: Nasser M. Abbasi

Date: 9 Nov, 2012 20:20:05

Message: 2 of 3

On 11/9/2012 1:57 PM, Gianluca wrote:
> Hi,
>
> I am new in matlab and I need some help to solve a simple equation. This is my code:
>
> clc
> clear all
>
> C=3.208; % Jacobi constant
> M1= 5.9736e24; % Mass of Earth in kg
> M2= 7.3477e22; % Mass of Moon in kg
> mu=M2/(M1+M2);
>
> for x=-4e6:10000:4e6;
> i=1:1:length(x);
>
> syms x y
>
> y(i)=solve(x(i).^2+y(i).^2+2*(1-mu)./sqrt((x(i)+mu).^2 + y(i).^2)+2*mu./sqrt((x(i)-1+mu).^2+y(i).^2)-C, y(i)); % solve the equation
> % for the y variable.
> end
>
> It's a very simple code but Matlab gives me the message:
>
> Warning: Explicit solution could not be found.
>> In solve at 83
>
> It doesn't gime an error; just this message. I don't know where I am wrong. Thanks a lot
>to anyone who will help me.
>
> Regards
>
> Gian
>

I think you are very confused by mixing syms and non-syms (as is the
case with most users of Matlab).

You say x=-4e6:10000:4e6 then you follow that with 'syms x y'
then you later use 'x' again as an array x(i).

Which is it? is 'x' a symbol, or a number or a vector?

Why not stick to one thing and do everything in numerics? Why not
use fsolve?

--Nasser

Subject: Problem solving equation

From: Gianluca

Date: 10 Nov, 2012 17:56:16

Message: 3 of 3

"Nasser M. Abbasi" <nma@12000.org> wrote in message <k7johr$7g8$1@speranza.aioe.org>...

> I think you are very confused by mixing syms and non-syms (as is the
> case with most users of Matlab).
>
> You say x=-4e6:10000:4e6 then you follow that with 'syms x y'
> then you later use 'x' again as an array x(i).
>
> Which is it? is 'x' a symbol, or a number or a vector?
>
> Why not stick to one thing and do everything in numerics? Why not
> use fsolve?
>
> --Nasser

--------------------------------------------------------------------------------------

Thanks for the reply Nasser. I'll try to explain you what I want to do. I want to solve that equation for the y variable, giving at every step the value of x. So x and y should be vectors. This is the only way I could think in order to solve the equation, giving at every step a different value of x, and obtaining the corrispondent value of y. Maybe you can suggest a simpler methods. I am still trying to learn how to use Matlab.

Thanks

Gian

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us