Solve a numerical equation using for loop
16 visualizaciones (últimos 30 días)
I'm trying to solve a numerical equation with with two variables x,y with for loop that are basically normalized of each other but I get the error below. I would really appreciate if someone could please help me. Here is the code and error message:
x = zeros(10,10);
y = zeros(10,10);
S = zeros(10,10);
syms x y
Conversion to double from struct is not possible.
Thanks in advance.
DGM el 7 de Abr. de 2021
Editada: DGM el 7 de Abr. de 2021
This might help:
S = struct('x',,'y',);
syms x y
% look at one result
You were trying to put structs into a numeric array. That doesn't work. You were also simultaneously trying to use x and y as symbolic variables and numeric arrays. When used as numeric arrays, they'd make eqn1 invalid, since you're asserting that a nonzero constant is equal to zero. Not only is there nothing to solve, it's a false assertion.
Preallocate a struct to put your results in, and just use syms for x and y.
The last issue is that I don't know how you hope to solve the equation x*y=k, where k is a constant. You only have one equation, so the solution is a curve -- the locus of an infinite number of solutions. You might be able to graph these curves and obtain some information about them, but using a solver really doesn't tell you the whole story. For emphasis:
% plot the solution locus for the first element
loglog(x,y); hold on; grid on
That's a line, not a point. There are infinitely many solutions to every one of these. vpasolve() will just give you one point on the line. It's lack of uniqueness likely makes the given solution meaningless in any particular application.