Cant make my syms function into a fsolve function

Hi
Since I've found out that:
syms
Doesn't work in matlab gui, I need to change my code, and Im totally new at the fsolve function, and dont quite how it works, do I need to make a function file to make it work, I've look at many tutorials from mathworks but I still can't make my script work. This is what I need to make into a fsolve function:
example:
L = 12;
A = 0.3;
vaegt = 60;
Rcd = 250;
slag = (1:80)';
test = zeros(size(slag));
syms x
for h = 1:length(slag)
S0 = sqrt((2*x*vaegt*L)/(A*20000000));
kraeft = @(x)((1/1.5).*vaegt.*x./((0.2./slag(h))+0.5*S0))./1.3;
test(h) = solve(kraeft(x)==(Rcd),x);
end
If someone also see a way to make it calculate faster that would be nice :).

 Respuesta aceptada

There is no problem using syms in a MATLAB GUI that is running interactively. There is only a problem if you attempt to compile or generate code.
Your system is effectively a quadratic, and has a pair of solutions:
(39/32000000000)*Rcd*(39*Rcd*slag*L +/- 39^(1/2)*(Rcd*slag*L*(39*L*Rcd*slag+640000000*A))^(1/2)+320000000*A)/(A*slag*vaegt)
There is no need to fsolve() at all.

4 comentarios

Mikkel Ibsen
Mikkel Ibsen el 4 de Dic. de 2017
Editada: Mikkel Ibsen el 4 de Dic. de 2017
Yeah its because I want to compile the matlab gui, and it just gives me an error when I try to calculate it. But you say I dont need to use fsolve?
Can you make it a little bit more explicit what I should do? the code you have pasted gives me an 80x80 matrix with alot of zeros.
What I dont understand when you say a pair of solutions, when I do it with syms, it only gives me 1 solution. I want the same thing with another way to do it, other than syms, so I can compile the gui.
Ive been looking for a way to just solve it with algabra but the function will be way to long and messy, isnt there a way to do it like Ive done with syms?
Make sure you vectorize the code
(39/32000000000) .* Rcd .* (39 .* Rcd .*slag .* L + 39.^(1/2) .* (Rcd .* slag .* L .* (39 .* L .* Rcd .* slag + 640000000 .* A)).^(1/2) + 320000000 .* A) ./ (A .* slag .* vaegt)
and
(39/32000000000) .* Rcd .* (39 .* Rcd .*slag .* L - 39.^(1/2) .* (Rcd .* slag .* L .* (39 .* L .* Rcd .* slag + 640000000 .* A)).^(1/2) + 320000000 .* A) ./ (A .* slag .* vaegt)
The first one gives the right result, but why is there two solutions when syms only gives one?
And did you make matlab do the algebra simplification? or another program like Maple?
>> syms L A vaegt Rcd slag x real
>> S0 = sqrt((2*x*vaegt*L)/(A*20000000));
>> S0
S0 =
((L*vaegt*x)/(10000000*A))^(1/2)
>> kraeft = @(x)((1/1.5).*vaegt.*x./((0.2./slag)+0.5*S0))./1.3;
>> solve(kraeft(x)==(Rcd),x)
Warning: Possibly spurious solutions.
> In symengine
In mupadengine/evalin (line 123)
In mupadengine/feval (line 182)
In solve (line 293)
Warning: Solutions are valid under the following conditions: slag*((39*L*Rcd*(320000000*A + 39*L*Rcd*slag -
390000000*Rcd*slag*((L*(640000000*A + 39*L*Rcd*slag))/(3900000000000000*Rcd*slag))^(1/2)))/(320000000000000000*A^2*slag))^(1/2) ~= -2/5 & 0
<= L*Rcd*slag*(640000000*A + 39*L*Rcd*slag);
slag*((39*L*Rcd*(320000000*A + 39*L*Rcd*slag + 390000000*Rcd*slag*((L*(640000000*A +
39*L*Rcd*slag))/(3900000000000000*Rcd*slag))^(1/2)))/(320000000000000000*A^2*slag))^(1/2) ~= -2/5 & 0 <= L*Rcd*slag*(640000000*A +
39*L*Rcd*slag). To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
> In solve>warnIfParams (line 508)
In solve (line 357)
ans =
(39*Rcd*(320000000*A + 39*L*Rcd*slag - 390000000*Rcd*slag*((L*(640000000*A + 39*L*Rcd*slag))/(3900000000000000*Rcd*slag))^(1/2)))/(32000000000*A*slag*vaegt)
(39*Rcd*(320000000*A + 39*L*Rcd*slag + 390000000*Rcd*slag*((L*(640000000*A + 39*L*Rcd*slag))/(3900000000000000*Rcd*slag))^(1/2)))/(32000000000*A*slag*vaegt)
At the moment I am not sure why the stepwise approach gives only one answer.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 4 de Dic. de 2017

Comentada:

el 4 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by