Info

This question is closed. Reopen it to edit or answer.

Solve for y when it cant figure it out in y=f(x) form. Need to solve in matlab function block in simulink

2 views (last 30 days)
X= [ 0.024 0.055] ;
% Equation need to solve
0.364*(Y-0.024)-(0.00060025-(0.009+Y)^2) = 0.048*(X-0.024)-0.07603

Answers (1)

Stephan
Stephan on 18 Jul 2018
Hi,
you can do so:
syms x y
% Starting Point
fun = 0.364*(y-0.024)-sqrt(0.00060025-(0.009+y)^2) == 0.048*(x-0.024)-0.07603;
% Equation y=f(x)
f(x) = rhs(isolate(fun,y))
% Function Handle for calcualtions in Matlab
fun_handle = matlabFunction(f)
% Matlab function Block for use in Simulink
new_system('my_system')
open_system('my_system')
matlabFunctionBlock('my_system/my_block',f)
This gives you 3 different solutions:
1. you get the equation in the format y=f(x)
f(x) =
(1092*x)/70781 + (- 36000000*x^2 + 97755000*x - 32131815832268837361321925/576460752303423488)^(1/2)/141562 - 4239293/141562000
2. You get a function handle to work with in Matlab
fun_handle =
function_handle with value:
@(x)x.*1.542786906090618e-2+sqrt(x.*9.7755e7-x.^2.*3.6e7-5.573981525e7).*7.064042610305025e-6-2.994654638956782e-2
3. you get a matlab function block for the use in simulink, which i could not test, since i did this in Matlab online.
To do this the symbolic math toolbox is required.
Best regards
  2 Comments
Jigar Chaudhary
Jigar Chaudhary on 23 Aug 2018
Thanks for the solution. I do not have symbolic math toolbox.
Can this is possible else with any other command.
Walter Roberson
Walter Roberson on 23 Aug 2018
For that particular function, you can use
[x.*1.542786906090618e-2-sqrt(x.*9.7755e7-x.^2.*3.6e7-5.573981525e7)./1.41562e5-2.994654638956782e-2;
x.*1.542786906090618e-2+sqrt(x.*9.7755e7-x.^2.*3.6e7-5.573981525e7)./1.41562e5-2.994654638956782e-2]
This gives the two roots,
Be careful: the results are complex outside of
6517/4800 - (49*70781^(1/2))/24000
(49*70781^(1/2))/24000 + 6517/4800
so unless you are certain that the inputs will be in that range, you might need to code calls to complex() in the expression in order for Simulink not to complain about incompatibilities.

This question is closed.

Community Treasure Hunt

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

Start Hunting!