error in matrix multiplication and integration

%%
clc;
clear;
syms x;
%pi = 180.;
% syms y_x;
% syms y_x_das;
L = 100.;
E = 29000. ;
c = 0.1*L;
d_0 = 5.;
d_1 = 2.*d_0;
d_x = 2.*d_0*(x/(2.*L));
b = 2.;
I_z = (b*d_x.^3)/12.;
G = 11000.;
A_x = b*d_x;
As = 5/6*A_x;
y_x = c*sin(2*pi*x/L);
y_x_das = diff(y_x);
theta_2 = atan(y_x_das);
Q_a = [-cos(theta_2) -sin(theta_2) 0];
Q_s = [-sin(theta_2) -cos(theta_2) 0];
Q_b = [-c*sin((2*pi*x)/L) x -1];
%%
%flexibility matrix
d1= sqrt(1 + y_x_das.^2).*((Q_a'.*Q_a)./(A_x*E));
d1_int = integral(@(x) d1(), 0, 100., 'ArrayValued', 1);
Error using superiorfloat
Inputs must be floats, namely single or double.

Error in integralCalc/iterateArrayValued (line 159)
outcls = superiorfloat(x,fxj);

Error in integralCalc/vadapt (line 130)
[q,errbnd] = iterateArrayValued(u,tinterval,pathlen);

Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);

Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);

9 Comments

I got this to run, although the integral may not exist.
When I went to plot ‘d1’ to see what the function looked like (thinking that perhaps the singularities would show themselves), I got a matrix size incompatibility error.
Using arrayfun to see what the matrices look like, they all appear to be NaN(3) for every value of ‘yv’.
That needs to be investigated —
%%
clc;
clear;
% syms x;
%pi = 180.;
% syms y_x;
% syms y_x_das;
L = 100.;
E = 29000. ;
c = 0.1*L;
d_0 = 5.;
d_1 = 2.*d_0;
d_x = @(x) 2.*d_0*(x/(2.*L));
b = 2.;
I_z = @(x) (b*d_x(x).^3)/12.;
G = 11000.;
A_x = @(x) b*d_x(x);
As = @(x) 5/6*A_x(x);
y_x = @(x) c*sin(2*pi*x/L);
y_x_das = @(x) gradient(y_x(x))./gradient(x);
theta_2 = @(x) atan(y_x_das(x));
Q_a = @(x) [-cos(theta_2(x)) -sin(theta_2(x)) 0];
Q_s = @(x) [-sin(theta_2(x)) -cos(theta_2(x)) 0];
Q_b = @(x) [-c*sin((2*pi*x)/L) x -1];
%%
%flexibility matrix
d1 = @(x) sqrt(1 + y_x_das(x).^2).*((Q_a(x)'.*Q_a(x))./(A_x(x)*E));
d1_int = integral(@(x)d1(x), 1E-8, 100., 'ArrayValued', 1)
Warning: Inf or NaN value encountered.
d1_int = 3×3
NaN NaN NaN NaN NaN NaN NaN NaN NaN
xv = linspace(0, 100);
yv = arrayfun(d1, xv, 'Unif',0);
yv{1}
ans = 3×3
NaN NaN NaN NaN NaN NaN NaN NaN NaN
yv{end}
ans = 3×3
NaN NaN NaN NaN NaN NaN NaN NaN NaN
.
Pi = sym(pi);
syms x real
L = 100.;
E = 29000. ;
c = 0.1*L;
d_0 = 5.;
d_1 = 2.*d_0;
d_x = @(x) 2.*d_0*(x/(2.*L));
b = 2.;
I_z = @(x) (b*d_x(x).^3)/12.;
G = 11000.;
A_x = @(x) b*d_x(x);
As = @(x) 5/6*A_x(x);
y_x = @(x) c*sin(2*Pi*x/L);
y_x_das = @(x) gradient(y_x(x))./gradient(x);
theta_2 = @(x) atan(y_x_das(x));
Q_a = @(x) [-cos(theta_2(x)) -sin(theta_2(x)) 0];
Q_s = @(x) [-sin(theta_2(x)) -cos(theta_2(x)) 0];
Q_b = @(x) [-c*sin((2*Pi*x)/L) x -1];
%%
%flexibility matrix
d1 = @(x) sqrt(1 + y_x_das(x).^2).*((Q_a(x)'.*Q_a(x))./(A_x(x)*E));
d1_x = d1(x)
d1_x = 
%d1_int = integral(@(x)d1(x), 1E-8, 100., 'ArrayValued', 1)
d1_int = int(d1_x, 1e-8, 100)
d1_int = 
vpa(d1_int)
ans = 
@Milan comment moved here:
Thanks alot, this works now!
@Milan question moved here:
Hello,
I got a 6*6 matrix in this format, how do I get this as a one single matrix?
[ 626.35, -97.77, -4756.45, -626.35, 97.77, -5020.31]
[ -97.77, 35.79, 2115.79, 97.77, -35.79, 1462.95]
[-4756.45, 2115.79, 142701.95, 4756.45, -2115.79, 68877.21]
[ -626.35, 97.77, 4756.45, 626.35, -97.77, 5020.31]
[ 97.77, -35.79, -2115.79, -97.77, 35.79, -1462.95]
[-5020.31, 1462.95, 68877.21, 5020.31, -1462.95, 77418.13]
The output might be written in this format - internally, it's a usual matrix.
@Milan comment moved here
But I want to present with in one bracket
Torsten
Torsten on 28 Oct 2022
Edited: Torsten on 28 Oct 2022
Could you include the code that gave this output for the matrix ?
And please don't use the answer button because you only make comments.
%unit inch, ksi,
clc;
clear;
close;
Pi = sym(pi);
syms x real
L = 100.;
E = 29000. ;
c = 0.1*L;
d_0 = 5.;
b = 2.;
d_1 = b*d_0;
d_x = @(x) 2.*d_0*(1-(x/(2.*L)));
b = 2.;
I_z = @(x) (b*d_x(x).^3)/12.;
G = 11000.;
A_x = @(x) b*d_x(x);
As = @(x) 5/6*A_x(x);
y_x = @(x) c*sin(2*Pi*x/L);
y_x_das = @(x) gradient(y_x(x))./gradient(x);
theta_2 = @(x) atan(y_x_das(x));
Q_a = @(x) [-cos(theta_2(x)) -sin(theta_2(x)) 0];
Q_s = @(x) [sin(theta_2(x)) -cos(theta_2(x)) 0];
Q_b = @(x) [-c*sin((2*Pi*x)/L) x -1];
%%
%flexibility matrix
d1 = @(x) sqrt(1 + y_x_das(x).^2).*((Q_a(x)'.*Q_a(x))./(A_x(x)*E));
d1_x = d1(x);
d1_int = int(d1_x, 1e-8, L);
d_11 = vpa(d1_int);
d2 = @(x) sqrt(1 + y_x_das(x).^2).*(Q_s(x)'.*Q_s(x))./(G*As(x));
d2_x = d2(x);
d2_int = int(d2_x, 1e-8, L);
d_22 = vpa(d2_int);
%no shear consideration
% G_noshear = Inf;
% d2_noshear = @(x) sqrt(1 + y_x_das(x).^2).*(Q_s(x)'.*Q_s(x))./(G_noshear*As(x));
% d2_x_noshear = d2_noshear(x);
% d2_int_noshear = int(d2_x, 1e-8, L);
% d_22_noshear = vpa(d2_int);
d_22_noshear = 0;
d3 = @(x) sqrt(1 + y_x_das(x).^2).*(Q_b(x)'.*Q_b(x)) ./(E*I_z(x));
d3_x = d3(x);
d3_int = int(d3_x, 1e-8, L);
d_33 = vpa(d3_int);
d = d_11+d_22+d_33; %flexibility matrix
d_noshear = d_11+d_33;
% equllibrium matrix
phi = [-1 0 0; 0 -1 0; 0 L -1];
%Siffness matrix
Kff = inv(d);
Kfs = inv(d)*phi';
Ksf = phi*inv(d);
Kss = phi*inv(d)*phi';
K = round([Kff Kfs; Ksf Kss], 2);
%no shear stiffness matrix
Kff_ns = inv(d_noshear);
Kfs_ns = inv(d_noshear)*phi';
Ksf_ns = phi*inv(d_noshear);
Kss_ns = phi*inv(d_noshear)*phi';
K_noshear = round([Kff_ns Kfs_ns; Ksf_ns Kss_ns], 2)
K_noshear = 
% K = [inv(d) inv(d).*phi';
% phi.*inv(d) phi.*inv(d).*phi'];
sdof = ([1, 2, 5]);
fdof = ([3,4,6]);
K_ff = K(fdof, fdof);
f_f = [300 100 0]';
delta_f = inv(K_ff)*f_f;
theta_z1 = round(delta_f(1,:),5);
mat2str() will show it with just one []
Note: mat2str() may lose the bottom bit of numbers. format long g loses the bottom bit of numbers. If you need to be able to exactly reproduce the array then you will need to create your own function to convert it.

Sign in to comment.

Answers (0)

Asked:

on 27 Oct 2022

Commented:

on 28 Oct 2022

Community Treasure Hunt

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

Start Hunting!