Hi,
I have symbolic integrations. (int_1 , int_2 inside t.m).
I need to solve an equation system with these integrations. First, I used fsolve. But it did not work since the integrations return complex values. Then I used vpasolve. The question is How trustable is vpasolve? If I use tlast =0.7, Matlab says :
Error using plot Vectors must be the same length.
If I use tlast= 0.77 it does not give me an error. However, the plot has strange looking.
I suspect that it does not calculate F when T=0.7 as the plot for harray and thetaarray versus Tarray should be smooth.
Is there any wayout for my problem. Codes are below
clear all; close all; clc; x0 = [.1, .1]; options = optimoptions('fsolve','Display','iter'); dt=0.07; M = .1; g = .01; Gamma = 0.2; I = Gamma*M; tlast = 0.7; Nt=tlast/dt+1; Tarray = [0:dt:tlast]; kappa = 1; b=0.6; h0 = kappa *b*(1-b); for nt=1:Nt T = (nt-1)*dt; X = sym('x', [1,2]); F = t(X,T,M,g,Gamma); sols = vpasolve(F, X); h_actual=sols.x1 theta_actual=sols.x2 h = double(sols.x1) theta = double(sols.x2) harray(nt) = h thetaarray(nt) = theta end figure(1) subplot(2,1,1) plot(Tarray,harray,'k') subplot(2,1,2) plot(Tarray,thetaarray,'k')
The function I used is
function F=t(x,T,M,g,Gamma)x_1=[0:0.01:1]b=0.6; syms x_1 h theta f_11 = 1-( (h+(x_1-b)*theta)^2/(h+(x_1-b)*theta-1*x_1*(1-x_1))^2 );f_21 = (x_1-b)/2*( 1-( (h+(1-b)*theta)^2/(h+(x_1-b)*theta-x_1*(1-x_1))^2 ));int_1 = int(f_11, x_1);int_2 = int(f_21, x_1);x_1=1;upper_1=subs(int_1);upper_2=subs(int_2);clear x_1;x_1=0;lower_1=subs(int_1);lower_2=subs(int_2);clear x_1;integral_result_1old=upper_1-lower_1;integral_result_2old=upper_2-lower_2;h0 = kappa *b*(1-b);theta0 = kappa*(1-2*b);integral_result_1 = subs(integral_result_1old, {h, theta}, {x(1), x(2)});integral_result_2 = subs(integral_result_2old, {h, theta}, {x(1), x(2)});F = [vpa(x(1) - (1/2*integral_result_1 - M*g)*T^2 -h0); vpa(x(2) - (1/(2*Gamma)*integral_result_2)*T^2 - theta0)];
Before using vpasolve I did use fsolve. However, it did not solve my problem for complex values. The function for fsolve does not allow to take T for inputs. Even if it allows, when I plot harray versus Tarray I get wrong plot. Is MAtlab capable of solving the system I have. Thanks..
Best Answer