I need to run the code written in the first following section for the variable "P" running from 400000 to 900000, then consider only the max( sol.y) value considered in the sol.x>50 and sol.x<180 range for every "P(i)" solution.
i've tried to fit the code in a for loop i=1:length(n) allocating a P(i) value to the P variable where n is a "linspace" vector but it is not correct, it says that is not possible to convert from sym to double.
Could someone help me please?
this is the code whitout the loop:
%variables:
P=0.5*800000;%kN -carico agente
R=20;%mm -raggio medio
L=3*75;%mm -lunghezza tubo
s=1;%mm -spessore di parete
ni=0.3;% -coeff poisson
E=210000;%MPa -modulo young
w=2;%MPa -pressione int/ext
K=0.5;% -incasto incastro
E1=E/(1-(ni^2));% -modulo young dilataz laterale impedita
I=(2*pi*R*(s^3))/12;% -momento di inerzia cilindro
k=2*pi*((E*s)/R);% -rigidezza molla fondazione
Pcr=sqrt(4*k*E1*I)% -carico critico
Pcre=((pi)^2*E*I)/(K*((L/1000)^2))% -carico critico secondo Eulero
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ODE:
f = @(z,u) [u(2); u(3); u(4); (-1/(E1*I))*((P*u(3))+(k*u(1)))]; bc = @(ua, ub) [ua(1); ua(2)-0.00000001; ub(1); ub(2)+0.00000001]; zmesh = linspace(0, L, 100000);iguess= @(z) [0; 0; 0; 0];solinit = bvpinit(zmesh,iguess ); opts = bvpset('RelTol',0.1,'AbsTol',0.1,'Stats','on'); sol= bvp4c(f, bc, solinit,opts);hold ongrid onplot(sol.x(1,:),sol.y(1,:))legend('w=0')xlabel('z');ylabel('solution u');
this is the for loop that should solve the differential equation f for every P value:
syms P;n=linspace(400000,900000);for i=1:length(n)f = @(z,u) [u(2); u(3); u(4); (-1/(E1*I))*((P(i)*u(3))+(k*u(1)))];bc = @(ua, ub) [ua(1); ua(2)-0.00000001; ub(1); ub(2)+0.00000001];zmesh = linspace(0, L, 100000);iguess= @(z) [0; 0; 0; 0];solinit = bvpinit(zmesh, iguess);Sol= bvp4c(f, bc, solinit);end
the section that finds the max of sol.y is:
x = sol.x;y = sol.y;idx = (x > 50) & (x < 180);x_new = x(idx);y_new = y(1, idx);y_new_max = max(y_new)
Best Answer