How to Use FindRoot for Determinant with Fixed Values?

  • Thread starter Reem Hashem
  • Start date
  • Tags
    Mathematica
In summary, you may want to try scaling your code down to a simpler form before you try to use find root.
  • #1
Reem Hashem
23
0
Hello, I need someone to help me with mathematica

my aim in the code I wrote is to find the value of "w" with fixed values of "a" and "z" which makes the determante det =0 so I need bisection method to find the value of w ,then I thought to use FindRoot function but it did not work. So how to use FindRoot function in this regard.

this my code (attached)
 

Attachments

  • my right systems.nb
    85.2 KB · Views: 606
Physics news on Phys.org
  • #2
If it helps, you can replace

f[1, 1] = y1[1] /. m;
f[1, 2] = y2[1] /. m;
f[1, 3] = y3[1] /. m;
f[1, 4] = y4[1] /. m;
f[2, 1] = y5[1] /. m;
f[2, 2] = y6[1] /. m;
f[2, 3] = y7[1] /. m;
f[2, 4] = y8[1] /. m;
f[3, 1] = y17[1] /. m;
f[3, 2] = y18[1] /. m;
f[3, 3] = y19[1] /. m;
f[3, 4] = y20[1] /. m;
f[4, 1] = y25[1] /. m;
f[4, 2] = y26[1] /. m;
f[4, 3] = y27[1] /. m;
f[4, 4] = y28[1] /. m;
d = Array[f, {4, 4}];
d = Partition[Flatten[d], 4];

with

d = First[{{y1[1], y2[1], y3[1], y4[1]},
{y5[1], y6[1], y7[1], y8[1]},
{y17[1], y18[1], y19[1], y20[1]},
{y25[1], y26[1], y27[1], y28[1]}} /. m]

Now more serious. You have

if (b > 0) {
w1 = w};
if (b < 0 & w == w1 + 100000) {
w2 = w1 + 100000;
FindRoot[{c, b}, {w, {w1, w2}}];
Print[ a, " " , z, " ", w, " ", b];
z = z + 0.2}

That sort of looks like you may have just made some manual changes for posting and that isn't really your original code. If really is what you are trying to do then that isn't Mathematica code. An attempt to translate that to Mathematica is

If[b > 0, w1 = w];
If[b < 0 && w == w1 + 100000,
w2 = w1 + 100000;
FindRoot[{c, b}, {w, {w1, w2}}];
Print[ a, " " , z, " ", w, " ", b];
z = z + 0.2
]

Mathematica uses {} and , and ; and If very differently from other programming languages.

Now we get to your error messages from FindRoot. Your first call to FindRoot is

FindRoot[{{-2.64486},-2.64486},{101000,{1000,101000}}]

If someone handed you that and asked you to find the root of that then what would you do?
There aren't any variables, it isn't a function of something that changes, it is just some nested constants.

Just for the very first one, what should the function be that you are trying to find a root of?

With that perhaps we can figure out what is going on.
 
  • #3
Reem Hashem said:
Hello, I need someone to help me with mathematica

my aim in the code I wrote is to find the value of "w" with fixed values of "a" and "z" which makes the determante det =0 so I need bisection method to find the value of w ,then I thought to use FindRoot function but it did not work. So how to use FindRoot function in this regard.

this my code (attached)

I can recommend a way of solving your problem but you may not like it:

It's way too messy. You got what, 30 in there with nested loops? This is a programmer's issue. You have got to get in the habit of chopping your code down and getting a simple version of it working before you make it complex. Then once you have a simple version, gradually add complexity to it until you bring it back to your desired version. So if this was my code, I'd scale it down to say four equations, take out all the loops, and just get it working for one case. Then introduce a single loop and get it working, then add another loop and continue adding complexity until I bring it back to where I want it. No guarantee that will work as scaling it down may remove some essential feature you need but it often does work.
 

FAQ: How to Use FindRoot for Determinant with Fixed Values?

How can I solve a specific equation in Mathematica?

To solve a specific equation in Mathematica, you can use the Solve function. Simply type in the equation and indicate what variable you want to solve for. For example, if you want to solve the equation x + 3 = 7 for x, you would type in Solve[x + 3 == 7, x] and Mathematica will give you the solution.

How do I plot a graph in Mathematica?

To plot a graph in Mathematica, you can use the Plot function. Specify the function or equation you want to graph and indicate the range of values for the x-axis. For example, if you want to graph the function y = x^2 from x = 0 to x = 5, you would type in Plot[x^2, {x, 0, 5}] and Mathematica will generate the graph for you.

Can Mathematica perform symbolic calculations?

Yes, Mathematica can perform symbolic calculations. It has a built-in system for symbolic manipulation of algebraic equations and expressions. This allows you to work with variables, equations, and functions in their exact form, rather than numerical approximations.

How can I import data into Mathematica?

You can import data into Mathematica using the Import function. This function allows you to import data from various file formats, such as CSV, Excel, or text files. You can also directly copy and paste data from a spreadsheet or other source into Mathematica.

Is there a way to speed up computations in Mathematica?

Yes, there are several ways to speed up computations in Mathematica. You can use the Compile function to compile your code into a form that can be executed more efficiently. Additionally, you can use parallel computing techniques to distribute the workload across multiple cores or processors, reducing computation time. There are also various optimization techniques that can be applied to specific types of calculations to improve efficiency.

Similar threads

Replies
3
Views
2K
Replies
5
Views
2K
Replies
1
Views
809
Replies
4
Views
2K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
3
Views
2K
Replies
4
Views
2K
Back
Top