Solving Nonlinear System of Equations for x and y as a Function of r

In summary, Prashant is trying to code a file in matlab which is a m-file. He is having trouble with the for subsystem and trying to figure out how to set the values for va which varies from 0 to 28-TAC/8 which has 200 divisions. He also wants to know how to give the incremented value of va each time during iteration.
  • #1
JohanL
158
0
1.
a line in my code is something like

int(phi*x^2,0,2)

where i want phi to be a function which the user
has choosen. But how can i let the user choose a function? For numbers you can use input but how to do
it with a function?

2.
i want to solve a nonlinear system of equations in x,y.

exp(-2x)*(2*r*x-1)+1=8*pi*r^2 (1)
exp(-2x)*(2*r*y+1)-1=8*pi*r^2

Do you have to specify r before you solve the system or can you get a solution as function of r,

x=f(r) (2)
y=g(r)

?

x and y are parameters in a spherical symmetric metric and r are the radius so i guess you need a solution like (2)? But is that possible in matlab? Do you need to solve the system for many different r's and then plot the x and y as a function a r?


Thank you.
 
Physics news on Phys.org
  • #2
1. I'm not a guru in Matlab but I don't think there is an equation parser. I know Matlab can work with other languages so maybe a code sequence in C or Java would solve your problem (in java you can find many examples on the internet ...like this one http://www.pyzdrowski.ws/asp/ictcm/graph.htm).

2. I would choose the second solution you give (solve the system for each value of r).
 
  • #3
Thanks for your help!
1. Couldnt find the source code for the equation parser tho. Is it easy when you have the source code in java to use it in your MATLAB code? Do you know how this is done?

2. I have written a code that i think should solve the system but i get an error message because of fsolve.

syms L e ;

for i=1:3

r = i;

G = 2*pi/r^2*int(int((1/L^5)*L^2/sqrt(L^2-L-e/r^2),e,0,r^2*(L^2-1)),1,inf)

H = 2*pi/r^2*int(int((1/L^5)*sqrt(L^2-L-e/r^2),e,0,r^2*(L^2-1)),1,inf)

F = inline('[exp(-2.*x(1)).*(2.*r.*x(1)-1)+1-8*pi.*r.^2*G;exp(-2.*x(1)).*(2.*r.*x(2)+1)-1-8*pi.*r.^2*H]','x'); % define function

x0 = [0; 0]; % Make a starting guess at the solution

X = fsolve(F,x0) % Call optimizer

end

I think I've tried everything but i can't figure it out.
The code works fine if i remove fsolve but with fsolve i get the error

? Error using ==> inlineeval
Error in inline expression ==> [exp(-2.*x(1)).*(2.*r.*x(1)-1)+1-8*pi.*r.^2*G;exp(-2.*x(1)).*(2.*r.*x(2)+1)-1-8*pi.*r.^2*H]
? Undefined function or variable 'r'.

Thank you
 
  • #4
I need a help from you people...by the way i am prashant from chennai...
my senior lecturer have given me a work to do as a final year project...
The work is to simulink a coded file which is a m-file in matlab. while doing so i come across various problems when implementing the "for iteration" in simulink...
I was using the for subsystem available in simulink in ports and subsystems...
In that Number of iterations can be given from an external source...


for G=0.2:0.2:1
Va =linespace(0,28-Tac/8,200)
Ia =solkar(Va,G,Tac)
plot(Va,Ia)

This is the m-file coding...This i need to do it in simulink...
how to set values for va which varies from 0 to 28-TAC/8 which has 200 divisions...
I mean how to give the incremented value of Va each time during iteration...
In short how to implement linespace in simulink...
 

1. How do you solve a nonlinear system of equations?

To solve a nonlinear system of equations for x and y as a function of r, you can use substitution or elimination methods. Substitution involves solving one equation for one variable and plugging that into the other equation. Elimination involves adding or subtracting equations to eliminate one variable and then solving for the remaining variable.

2. What is the importance of solving a nonlinear system of equations?

Solving a nonlinear system of equations can help us find the values of the variables that satisfy all the equations, and thus provide a solution to a real-life problem. It is also important in fields such as physics and engineering, where nonlinear equations often arise in modeling complex systems.

3. Can a nonlinear system of equations have more than one solution?

Yes, a nonlinear system of equations can have more than one solution. This is because the equations may intersect at multiple points, or they may have infinitely many solutions. In some cases, there may also be no solution to the system.

4. What are the challenges of solving a nonlinear system of equations?

One challenge is that there is no one universal method for solving all types of nonlinear systems. Different methods may work better for certain types of equations, and it may require trial and error to find the best approach. Another challenge is that the solutions may involve complex numbers, which can be difficult to work with.

5. Are there any tips for solving a nonlinear system of equations?

Some tips for solving a nonlinear system of equations include: carefully analyzing the equations to determine the best method to use, starting with simpler equations and gradually building up to more complex ones, and using a graphing calculator or software to visualize the equations and their solutions. It is also important to check the solutions by plugging them back into the original equations to ensure they satisfy all the equations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
997
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
261
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Special and General Relativity
Replies
5
Views
360
Back
Top