Error using plot Conversion to double from sym is not possible. Error in MAE315_Intro_Project (line 66) plot(epsil​on,sigma,R​epsilon,Rs​igma,'o').

Does anybody know why I am getting those errors? I cannot figure it out at all. Any help would be greatly appreciated. Thanks! See below for my code.
clear all; close all; clc;
load data
syms F t w
% Uncertainties
u_F = F .* 0.01
u_m = 0.001/2
% Equations for Uncertainty
A = t.*w; % Area
sigma = F./A % Stress
% Uncertainty
u_sigma = sqrt((diff(sigma,F).*u_F).^2 + (diff(sigma,t).*u_m).^2 +...
(diff(sigma,w).*u_m).^2)
% Givens
D = Dat(1:1953,1);
F = Dat(1:1953,2);
t = 0.094; % Thickness, inches
w = 0.370; % Width, inches
l = 6.500; % Length, inches
L = l + D; % Displaced Length
epsilon = (L - l)./l %Strain
sigma = subs(sigma)
u_sigma = subs(u_sigma)
% Plot Stress vs Strain
figure (1)
plot(epsilon, sigma)
xlabel('Strain')
ylabel('Stress')
title('Stress vs Strain')
% Ultimate Stress
Usigma = max(sigma)
% Ultimate Strain
index = find(sigma==Usigma)
Uepsilon = epsilon(index)
% Plot Ultimate Stress and Strain
figure (2)
plot(epsilon,sigma,epsilon(index),Usigma,'o')
xlabel('Strain')
ylabel('Stress')
title('Ultimate Stress & Ultimate Stress Point')
% Rupture Stress
Fm = Dat(1953:1953,2); % Max Force
Rsigma = Fm./A
% Rupture Strain
Dm = Dat(1953:1953,1); % Max Displacement
Lm = l + Dm; % Max New Length after Max Displacement
Repsilon = (Lm - l)./l
% Plot Rupture Stress and Strain
figure (3)
plot(epsilon,sigma,Repsilon,Rsigma,'o')
xlabel('Strain')
ylabel('Stress')
title('Rupture Stress & Rupture Stress Point')

 Accepted Answer

It’s best to not use the Symbolic Math Toolbox functions unless you need to do symbolic operations. It’s not intended for routine numerical computation.
What variables are you loading from your ‘data’ file?
I can’t run your code, so I can’t experiment with it. However, I would put everything before the ‘%Givens’ after them instead (except the load call). Then you could completely avoid the Symbolic Toolbox function calls (such as subs) and the problems they create for you later.

8 Comments

Thanks for your response Star Strider. What would you do to solve the uncertainty part then if not syms? The entire code was working fine before I got into the uncertainty stage of things. I'm very confused now. I have attached the data file. It's all the displacements and forces for the problem.
I would put the uncertainty calculations after the ‘epsilon’ assignment, since it looks as though all the variables are assigned by then.
It would be best to use the Symbolic Math Toolbox to calculate ‘u_sigma’ since it involves significant derivative calculations, then use the matlabFunction function to turn it into an anonymous function. Print that to the Command Window and then copy-paste it to your code.
If you need to do essential function definitions, instead of using the Symbolic Math Toolbox, use Anonymous Functions. They’ll do what you want, and won’t cause the incompatibilities the Symbolic Math Toolbox can.
I'm not sure I follow you. I moved the uncertainty stuff down after the 'epsilon' assignment. I'm getting these two errors now:
Error using diff Difference order N must be a positive integer scalar.
Error in MAE315_Intro_Project (line 28) u_sigma = sqrt((diff(sigma,F).*u_F).^2 + (diff(sigma,t).*u_m).^2 +...
Any ideas? I've been so stuck on solving this uncertainty equation.
When sigma is numeric, diff(sigma,F) is going to be successive differences, not derivative. diff() means derivative when the first argument is symbolic.
The u_sigma is the exception that I noted earlier:
‘It would be best to use the Symbolic Math Toolbox to calculate ‘u_sigma’ since it involves significant derivative calculations, then use the matlabFunction function to turn it into an anonymous function. Print that to the Command Window and then copy-paste it to your code.’
The rest of the uncertainty calculations seem to be relatively straightforward once your code defines the variables they use.
Okay so I finally got this uncertainty portion to work. Thank you for both of your help. I still however cannot get the last plot to plot. It's giving me the same error I had originally in the question.
Do either of you understand what that error means? And how I can fix it? Thanks.
Yes.
Don’t use the Symbolic Toolbox for this. Once you have anonymous functions for ‘u_sigma’ and any others you may need, evaluate them as strictly numeric vectors and plot them.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!