Live script error - Error in state of SceneNode

38 views (last 30 days)
Ron
Ron on 7 Dec 2024 at 14:55
Commented: Ron on 8 Dec 2024 at 4:05
I'm evaluating Symbolic Math Toolbox, but can't get the following to run without error:
syms u(t)
[V] = odeToVectorField(diff(u,2) == u -(1/5)*u^3 + cos(t)
M = matlabFunction(V, 'Vars', {'t', 'Y'})
sol = ode45(M, [0 20],[0 0])
fplot(@(t)deval(sol,t,1), [0, 20])
xlabel("time")
ylabel("solution")
Plot gives 'Warning: Error in state of SceneNode
The following error was reported evaluating the function in Functiion
  • Not sure how to deal with this snce running the same code in a different live script works OK, unless I increase the plotting interval beyond 20
  • I'm new to this add on and would be grateful for any help in understanding the syntax used by toolbox
Many thanks for you help.
  2 Comments
Walter Roberson
Walter Roberson on 7 Dec 2024 at 22:19
"Error in state of SceneNode" usually occurs when a text or label or title or tick label Interpreter is set to LaTex, but the corresponding string is not valid LaTex code (as far as the basic latex interpretation goes.)
An example of the error is
txt = sprintf('$T=%.1f%c$C', T(i), char(176));
text(Nodes(i,1), Nodes(i, 2), txt , 'Interpreter','latex');
This uses a character position beyond 127, but LaTex intepreter can only process characters up to code position 127.
Ron
Ron on 8 Dec 2024 at 1:42
I don't see anything in the code that is text beyond ascii 127. I wonder if it has something to do with the fact that my matlab is R204b, and Symbolic Math Toolbox 24.2. Anyway thanks for replying.

Sign in to comment.

Accepted Answer

Anjaneyulu Bairi
Anjaneyulu Bairi on 7 Dec 2024 at 16:36
Hi,
When I attempted to run the code you provided, it did not initially display any errors as you mentioned. However, I encountered a syntax error related to "odeToVectorField." After adjusting the syntax, the code executed without any issues.
I recommend uninstalling the add-on and then reinstalling it. If the error persists, consider using alternative solvers such as "ode15s" or "ode23".
Here is the output of the code execution:
syms u(t)
[V] = odeToVectorField(diff(u,2) == u -(1/5)*u^3 + cos(t)) % Modified line to remove syntax error.
% number of parentheses were not matching
M = matlabFunction(V, 'Vars', {'t', 'Y'})
M = function_handle with value:
@(t,Y)[Y(2);cos(t)-Y(1).^3./5.0+Y(1)]
sol = ode45(M, [0 20],[0 0])
sol = struct with fields:
solver: 'ode45' extdata: [1x1 struct] x: [0 2.0095e-04 0.0012 0.0062 0.0313 0.1569 0.7508 1.5690 2.5427 3.0128 3.4829 3.9216 4.4227 5.1243 6.0899 6.7273 7.2162 7.7051 8.1551 8.7221 9.5564 ... ] (1x46 double) y: [2x46 double] stats: [1x1 struct] idata: [1x1 struct]
fplot(@(t)deval(sol,t,1), [0, 20])
xlabel("time")
ylabel("solution")
Hope it helps!
  1 Comment
Ron
Ron on 8 Dec 2024 at 4:05
I simply re-typed the [V] line and now all is well. Must have been some hidden character (like Alt255) embedd. Anyway, thanks for your help, it runs OK now.

Sign in to comment.

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!