When I run my code, I keep getting this error: "Undefined function or variable 'y'."
1 次查看(过去 30 天)
显示 更早的评论
Nauryzbay
2023-5-26
close all;clc
tspan = [0 1];
y0(1)=2;
y0(2)=1;
y0(3)=3;
source = 0;
tol = 1e-3;%Критерии допуска для определения наилучшей стоимости Мой критерий остановки - Tol= 1e-3.
error = 1.0;%Начальная ошибка запуска
while error > tol%ЗАПУСТИТЕ ЦИКЛ WHILE
sol = ode45(@(t,y) ode2(t,y,source), [0 1], y0);% ВЫЗЫВАЕМ СОЛВЕР BVP4C:
t = linspace(0,1,100);
source_new = trapz(t,y(3,:));
error = abs(source_new - source);
source = source_new;
end
figure(1);
subplot(3,1,1)
plot(sol.x,sol.y(1,:),'color','r','Linewidth',1.2);
grid on
hold on
xlabel('\bf t'); ylabel('$$y$$','interpreter','latex','fontsize',16);
subplot(3,1,2)
plot(sol.x,sol.y(2,:),'color','r','Linewidth',1.2);
grid on
hold on
xlabel('\bf t'); ylabel('$$\dot{y}$$','interpreter','latex','fontsize',16);
subplot(3,1,3)
plot(sol.x,sol.y(3,:),'color','r','Linewidth',1.2);
grid on
hold on
xlabel('\bf t'); ylabel('$$y"$$','interpreter','latex','fontsize',16);
function dy = ode2(~,y,source)%y''+y'=1+int^1_0(y'*x)dx;y(0) = 2;y(1) = 4;
m=0.05;
dy = zeros(3,1); % создает нулевой вектор-столбец
dy(1)=y(2);
dy(2)=y(3);
dy(3)=-3/m*y(3)+1/(m.^2)*(1-2*y(2)+4.*source);
end
Undefined function or variable 'y'.
Error in IDTinitial6 (line 14)
source_new = trapz(t,y(3,:));
采纳的回答
Walter Roberson
2023-5-26
Later you keep referring to sol.y so perhaps the reference to y should instead be to sol.y
7 个评论
Walter Roberson
2023-5-27
Fixing the undefined variable is easy, but the mathematics of your ode needs work. Your algorithm is diverging instead of converging.
close all;clc
tspan = [0 1];
y0(1)=2;
y0(2)=1;
y0(3)=3;
source = 0;
tol = 1e-3;%Критерии допуска для определения наилучшей стоимости Мой критерий остановки - Tol= 1e-3.
error = 1.0;%Начальная ошибка запуска
while error > tol%ЗАПУСТИТЕ ЦИКЛ WHILE
sol = ode45(@(t,y) ode2(t,y,source), [0 1], y0);% ВЫЗЫВАЕМ СОЛВЕР BVP4C:
source_new = trapz(sol.x,sol.y(3,:))
error = abs(source_new - source);
source = source_new;
end
source_new = -0.4960
source_new = -1.4832
source_new = -3.4532
source_new = -7.3810
source_new = -15.2412
source_new = -30.9274
source_new = -62.3157
source_new = -125.0048
source_new = -250.3451
source_new = -500.8211
source_new = -1.0024e+03
source_new = -2.0060e+03
source_new = -4.0171e+03
source_new = -8.0425e+03
source_new = -1.6109e+04
source_new = -3.2256e+04
source_new = -6.4619e+04
source_new = -1.2943e+05
source_new = -2.5923e+05
source_new = -5.1956e+05
source_new = -1.0406e+06
source_new = -2.0842e+06
source_new = -4.1744e+06
source_new = -8.3658e+06
source_new = -1.6762e+07
source_new = -3.3573e+07
source_new = -6.7243e+07
source_new = -1.3467e+08
source_new = -2.6983e+08
source_new = -5.4043e+08
source_new = -1.0829e+09
source_new = -2.1688e+09
source_new = -4.3461e+09
source_new = -8.7047e+09
source_new = -1.7436e+10
source_new = -3.4934e+10
source_new = -6.9966e+10
source_new = -1.4019e+11
source_new = -2.8076e+11
source_new = -5.6263e+11
source_new = -1.1269e+12
source_new = -2.2572e+12
source_new = -4.5224e+12
source_new = -9.0576e+12
source_new = -1.8148e+13
source_new = -3.6347e+13
source_new = -7.2834e+13
source_new = -1.4587e+14
source_new = -2.9220e+14
source_new = -5.8544e+14
source_new = -1.1726e+15
source_new = -2.3494e+15
source_new = -4.7052e+15
source_new = -9.4285e+15
source_new = -1.8883e+16
source_new = -3.7848e+16
source_new = -7.5831e+16
source_new = -1.5188e+17
source_new = -3.0431e+17
source_new = -6.0947e+17
source_new = -1.2212e+18
source_new = -2.4458e+18
source_new = -4.9019e+18
source_new = -9.8185e+18
source_new = -1.9666e+19
source_new = -3.9402e+19
source_new = -7.8914e+19
source_new = -1.5812e+20
source_new = -3.1668e+20
source_new = -6.3466e+20
source_new = -1.2712e+21
source_new = -2.5461e+21
source_new = -5.1014e+21
source_new = -1.0217e+22
source_new = -2.0472e+22
source_new = -4.1000e+22
source_new = -8.2165e+22
source_new = -1.6457e+23
source_new = -3.2963e+23
source_new = -6.6044e+23
source_new = -1.3227e+24
source_new = -2.6503e+24
source_new = -5.3080e+24
source_new = -1.0637e+25
source_new = -2.1304e+25
source_new = -4.2673e+25
source_new = -8.5499e+25
source_new = -1.7124e+26
source_new = -3.4311e+26
source_new = -6.8716e+26
source_new = -1.3770e+27
source_new = -2.7579e+27
source_new = -5.5242e+27
source_new = -1.1068e+28
source_new = -2.2168e+28
source_new = -4.4417e+28
source_new = -8.8956e+28
source_new = -1.7825e+29
source_new = -3.5701e+29
source_new = -7.1556e+29
source_new = -1.4337e+30
source_new = -2.8715e+30
source_new = -5.7534e+30
source_new = -1.1523e+31
source_new = -2.3089e+31
source_new = -4.6242e+31
source_new = -9.2679e+31
source_new = -1.8564e+32
source_new = -3.7181e+32
source_new = -7.4497e+32
source_new = -1.4920e+33
source_new = -2.9896e+33
source_new = -5.9874e+33
source_new = -1.1999e+34
source_new = -2.4034e+34
source_new = -4.8139e+34
source_new = -9.6452e+34
source_new = -1.9317e+35
source_new = -3.8706e+35
source_new = -7.7518e+35
source_new = -1.5535e+36
source_new = -3.1115e+36
source_new = -6.2323e+36
source_new = -1.2487e+37
source_new = -2.5009e+37
source_new = -5.0110e+37
source_new = -1.0036e+38
source_new = -2.0111e+38
source_new = -4.0281e+38
source_new = -8.0683e+38
source_new = -1.6166e+39
source_new = -3.2377e+39
source_new = -6.4872e+39
source_new = -1.2992e+40
source_new = -2.6035e+40
source_new = -5.2145e+40
source_new = -1.0445e+41
source_new = -2.0927e+41
source_new = -4.1914e+41
source_new = -8.3981e+41
source_new = -1.6819e+42
source_new = -3.3703e+42
source_new = -6.7501e+42
source_new = -1.3530e+43
source_new = -2.7108e+43
source_new = -5.4294e+43
source_new = -1.0878e+44
source_new = -2.1787e+44
source_new = -4.3657e+44
source_new = -8.7434e+44
source_new = -1.7524e+45
source_new = -3.5111e+45
source_new = -7.0324e+45
source_new = -1.4090e+46
source_new = -2.8219e+46
source_new = -5.6545e+46
source_new = -1.1325e+47
source_new = -2.2696e+47
source_new = -4.5459e+47
source_new = -9.1052e+47
source_new = -1.8243e+48
source_new = -3.6537e+48
source_new = -7.3210e+48
source_new = -1.4662e+49
source_new = -2.9384e+49
source_new = -5.8853e+49
source_new = -1.1788e+50
source_new = -2.3619e+50
source_new = -4.7303e+50
source_new = -9.4781e+50
source_new = -1.8982e+51
source_new = -3.8040e+51
source_new = -7.6190e+51
source_new = -1.5261e+52
source_new = -3.0577e+52
source_new = -6.1240e+52
source_new = -1.2270e+53
source_new = -2.4574e+53
source_new = -4.9245e+53
source_new = -9.8631e+53
source_new = -1.9756e+54
source_new = -3.9583e+54
source_new = -7.9279e+54
source_new = -1.5885e+55
source_new = -3.1813e+55
source_new = -6.3749e+55
source_new = -1.2768e+56
source_new = -2.5592e+56
source_new = -5.1275e+56
source_new = -1.0270e+57
source_new = -2.0577e+57
source_new = -4.1210e+57
source_new = -8.2578e+57
source_new = -1.6539e+58
source_new = -3.3148e+58
source_new = -6.6415e+58
source_new = -1.3302e+59
source_new = -2.6652e+59
source_new = -5.3378e+59
source_new = -1.0696e+60
source_new = -2.1421e+60
source_new = -4.2931e+60
source_new = -8.5990e+60
source_new = -1.7223e+61
source_new = -3.4509e+61
source_new = -6.9113e+61
source_new = -1.3848e+62
source_new = -2.7735e+62
source_new = -5.5582e+62
source_new = -1.1133e+63
source_new = -2.2299e+63
source_new = -4.4677e+63
source_new = -8.9479e+63
source_new = -1.7929e+64
source_new = -3.5907e+64
source_new = -7.1958e+64
source_new = -1.4412e+65
source_new = -2.8868e+65
source_new = -5.7840e+65
source_new = -1.1584e+66
source_new = -2.3211e+66
source_new = -4.6486e+66
source_new = -9.3154e+66
source_new = -1.8658e+67
source_new = -3.7372e+67
source_new = -7.4878e+67
source_new = -1.4997e+68
source_new = -3.0048e+68
source_new = -6.0179e+68
source_new = -1.2059e+69
source_new = -2.4152e+69
source_new = -4.8379e+69
source_new = -9.6932e+69
source_new = -1.9414e+70
source_new = -3.8899e+70
source_new = -7.7905e+70
source_new = -1.5611e+71
source_new = -3.1265e+71
source_new = -6.2664e+71
source_new = -1.2555e+72
source_new = -2.5147e+72
source_new = -5.0385e+72
source_new = -1.0091e+73
source_new = -2.0220e+73
source_new = -4.0496e+73
source_new = -8.1161e+73
source_new = -1.6256e+74
source_new = -3.2560e+74
source_new = -6.5238e+74
source_new = -1.3066e+75
source_new = -2.6180e+75
source_new = -5.2432e+75
source_new = -1.0508e+76
source_new = -2.1047e+76
source_new = -4.2156e+76
source_new = -8.4464e+76
source_new = -1.6916e+77
source_new = -3.3895e+77
source_new = -6.7883e+77
source_new = -1.3604e+78
source_new = -2.7247e+78
source_new = -5.4576e+78
source_new = -1.0935e+79
source_new = -2.1900e+79
source_new = -4.3881e+79
source_new = -8.7883e+79
source_new = -1.7611e+80
source_new = -3.5273e+80
source_new = -7.0653e+80
source_new = -1.4156e+81
source_new = -2.8352e+81
source_new = -5.6808e+81
source_new = -1.1377e+82
source_new = -2.2799e+82
source_new = -4.5662e+82
source_new = -9.1464e+82
source_new = -1.8326e+83
source_new = -3.6704e+83
source_new = -7.3541e+83
source_new = -1.4728e+84
source_new = -2.9513e+84
source_new = -5.9109e+84
source_new = -1.1847e+85
source_new = -2.3737e+85
source_new = -4.7543e+85
source_new = -9.5259e+85
source_new = -1.9078e+86
source_new = -3.8228e+86
source_new = -7.6562e+86
source_new = -1.5345e+87
source_new = -3.0735e+87
source_new = -6.1560e+87
source_new = -1.2334e+88
source_new = -2.4703e+88
source_new = -4.9498e+88
source_new = -9.9132e+88
source_new = -1.9867e+89
source_new = -3.9793e+89
source_new = -7.9703e+89
source_new = -1.5969e+90
source_new = -3.1983e+90
source_new = -6.4085e+90
source_new = -1.2835e+91
source_new = -2.5721e+91
source_new = -5.1517e+91
source_new = -1.0319e+92
source_new = -2.0675e+92
source_new = -4.1407e+92
source_new = -8.2967e+92
source_new = -1.6616e+93
source_new = -3.3298e+93
source_new = -6.6692e+93
source_new = -1.3359e+94
source_new = -2.6765e+94
source_new = -5.3606e+94
source_new = -1.0741e+95
source_new = -2.1511e+95
source_new = -4.3106e+95
source_new = -8.6335e+95
source_new = -1.7293e+96
source_new = -3.4649e+96
source_new = -6.9396e+96
source_new = -1.3905e+97
source_new = -2.7847e+97
source_new = -5.5802e+97
source_new = -1.1176e+98
source_new = -2.2401e+98
source_new = -4.4882e+98
source_new = -8.9893e+98
source_new = -1.8011e+99
source_new = -3.6072e+99
source_new = -7.2281e+99
source_new = -1.4476e+100
source_new = -2.9014e+100
source_new = -5.8132e+100
source_new = -1.1643e+101
source_new = -2.3329e+101
source_new = -4.6722e+101
source_new = -9.3620e+101
source_new = -1.8750e+102
source_new = -3.7577e+102
source_new = -7.5265e+102
source_new = -1.5075e+103
source_new = -3.0205e+103
source_new = -6.0493e+103
source_new = -1.2121e+104
source_new = -2.4276e+104
source_new = -4.8649e+104
source_new = -9.7441e+104
source_new = -1.9517e+105
source_new = -3.9105e+105
source_new = -7.8318e+105
source_new = -1.5693e+106
source_new = -3.1428e+106
source_new = -6.2982e+106
source_new = -1.2615e+107
source_new = -2.5267e+107
source_new = -5.0625e+107
source_new = -1.0139e+108
source_new = -2.0316e+108
source_new = -4.0687e+108
source_new = -8.1533e+108
source_new = -1.6330e+109
source_new = -3.2710e+109
source_new = -6.5537e+109
source_new = -1.3126e+110
source_new = -2.6300e+110
source_new = -5.2672e+110
source_new = -1.0555e+111
source_new = -2.1139e+111
source_new = -4.2371e+111
source_new = -8.4894e+111
source_new = -1.7003e+112
source_new = -3.4068e+112
source_new = -6.8230e+112
source_new = -1.3672e+113
source_new = -2.7382e+113
source_new = -5.4881e+113
source_new = -1.0996e+114
source_new = -2.2024e+114
source_new = -4.4127e+114
source_new = -8.8376e+114
source_new = -1.7709e+115
source_new = -3.5466e+115
source_new = -7.1079e+115
source_new = -1.4237e+116
source_new = -2.8516e+116
source_new = -5.7134e+116
source_new = -1.1443e+117
source_new = -2.2928e+117
source_new = -4.5919e+117
source_new = -9.2025e+117
source_new = -1.8432e+118
source_new = -3.6919e+118
source_new = -7.3970e+118
source_new = -1.4815e+119
source_new = -2.9684e+119
source_new = -5.9450e+119
source_new = -1.1914e+120
source_new = -2.3862e+120
source_new = -4.7795e+120
source_new = -9.5762e+120
source_new = -1.9179e+121
source_new = -3.8429e+121
source_new = -7.6964e+121
source_new = -1.5423e+122
source_new = -3.0890e+122
source_new = -6.1874e+122
source_new = -1.2397e+123
source_new = -2.4829e+123
source_new = -4.9749e+123
source_new = -9.9635e+123
source_new = -1.9966e+124
source_new = -3.9988e+124
source_new = -8.0099e+124
source_new = -1.6048e+125
source_new = -3.2143e+125
source_new = -6.4403e+125
source_new = -1.2898e+126
source_new = -2.5846e+126
source_new = -5.1764e+126
source_new = -1.0375e+127
source_new = -2.0787e+127
source_new = -4.1635e+127
source_new = -8.3420e+127
source_new = -1.6707e+128
source_new = -3.3477e+128
source_new = -6.7047e+128
source_new = -1.3437e+129
source_new = -2.6915e+129
source_new = -5.3908e+129
source_new = -1.0801e+130
source_new = -2.1632e+130
source_new = -4.3345e+130
source_new = -8.6809e+130
source_new = -1.7397e+131
source_new = -3.4846e+131
source_new = -6.9795e+131
source_new = -1.3984e+132
source_new = -2.8007e+132
source_new = -5.6118e+132
source_new = -1.1239e+133
source_new = -2.2523e+133
source_new = -4.5112e+133
source_new = -9.0359e+133
source_new = -1.8104e+134
source_new = -3.6259e+134
source_new = -7.2652e+134
source_new = -1.4550e+135
source_new = -2.9158e+135
source_new = -5.8400e+135
source_new = -1.1698e+136
source_new = -2.3437e+136
source_new = -4.6941e+136
source_new = -9.4053e+136
source_new = -1.8836e+137
source_new = -3.7746e+137
source_new = -7.5600e+137
source_new = -1.5143e+138
source_new = -3.0341e+138
source_new = -6.0768e+138
source_new = -1.2176e+139
source_new = -2.4385e+139
source_new = -4.8863e+139
source_new = -9.7863e+139
source_new = -1.9615e+140
source_new = -3.9300e+140
source_new = -7.8714e+140
source_new = -1.5771e+141
source_new = -3.1586e+141
source_new = -6.3292e+141
source_new = -1.2676e+142
source_new = -2.5405e+142
source_new = -5.0886e+142
source_new = -1.0192e+143
source_new = -2.0421e+143
source_new = -4.0898e+143
source_new = -8.1950e+143
source_new = -1.6413e+144
source_new = -3.2893e+144
source_new = -6.5882e+144
source_new = -1.3196e+145
source_new = -2.6439e+145
source_new = -5.2952e+145
source_new = -1.0610e+146
source_new = -2.1249e+146
source_new = -4.2584e+146
source_new = -8.5293e+146
source_new = -1.7084e+147
source_new = -3.4229e+147
source_new = -6.8554e+147
source_new = -1.3736e+148
source_new = -2.7510e+148
source_new = -5.5129e+148
source_new = -1.1042e+149
source_new = -2.2117e+149
source_new = -4.4313e+149
source_new = -8.8751e+149
source_new = -1.7783e+150
source_new = -3.5614e+150
source_new = -7.1367e+150
source_new = -1.4294e+151
source_new = -2.8631e+151
source_new = -5.7365e+151
source_new = -1.1489e+152
source_new = -2.3021e+152
source_new = -4.6105e+152
source_new = -9.2386e+152
source_new = -1.8503e+153
source_new = -3.7087e+153
source_new = -7.4307e+153
source_new = -1.4883e+154
source_new = -2.9820e+154
source_new = -5.9721e+154
source_new = -1.1967e+155
source_new = -2.3967e+155
source_new = -4.8036e+155
source_new = -9.6245e+155
source_new = -1.9277e+156
source_new = -3.8624e+156
source_new = -7.7354e+156
source_new = -1.5500e+157
source_new = -3.1042e+157
source_new = -6.2213e+157
source_new = -1.2461e+158
source_new = -2.4959e+158
source_new = -5.0007e+158
source_new = -1.0015e+159
source_new = -2.0068e+159
source_new = -4.0191e+159
source_new = -8.0545e+159
source_new = -1.6133e+160
source_new = -3.2313e+160
source_new = -6.4742e+160
source_new = -1.2967e+161
source_new = -2.5981e+161
source_new = -5.2033e+161
source_new = -1.0427e+162
source_new = -2.0885e+162
source_new = -4.1832e+162
source_new = -8.3815e+162
source_new = -1.6787e+163
source_new = -3.3635e+163
source_new = -6.7362e+163
source_new = -1.3499e+164
source_new = -2.7036e+164
source_new = -5.4154e+164
source_new = -1.0850e+165
source_new = -2.1732e+165
source_new = -4.3542e+165
source_new = -8.7204e+165
source_new = -1.7475e+166
source_new = -3.4998e+166
source_new = -7.0150e+166
source_new = -1.4055e+167
source_new = -2.8151e+167
source_new = -5.6404e+167
source_new = -1.1296e+168
source_new = -2.2636e+168
source_new = -4.5334e+168
source_new = -9.0861e+168
source_new = -1.8205e+169
source_new = -3.6463e+169
source_new = -7.3057e+169
source_new = -1.4632e+170
source_new = -2.9318e+170
source_new = -5.8717e+170
source_new = -1.1768e+171
source_new = -2.3571e+171
source_new = -4.7211e+171
source_new = -9.4591e+171
source_new = -1.8944e+172
source_new = -3.7960e+172
source_new = -7.6024e+172
source_new = -1.5236e+173
source_new = -3.0516e+173
source_new = -6.1123e+173
source_new = -1.2246e+174
source_new = -2.4527e+174
source_new = -4.9145e+174
source_new = -9.8425e+174
source_new = -1.9724e+175
source_new = -3.9506e+175
source_new = -7.9130e+175
source_new = -1.5854e+176
source_new = -3.1753e+176
source_new = -6.3623e+176
source_new = -1.2742e+177
source_new = -2.5534e+177
source_new = -5.1142e+177
source_new = -1.0244e+178
source_new = -2.0525e+178
source_new = -4.1107e+178
source_new = -8.2365e+178
source_new = -1.6496e+179
source_new = -3.3055e+179
source_new = -6.6204e+179
source_new = -1.3261e+180
source_new = -2.6570e+180
source_new = -5.3216e+180
source_new = -1.0662e+181
source_new = -2.1354e+181
source_new = -4.2790e+181
source_new = -8.5700e+181
source_new = -1.7177e+182
source_new = -3.4415e+182
source_new = -6.8930e+182
source_new = -1.3811e+183
source_new = -2.7660e+183
source_new = -5.5425e+183
source_new = -1.1100e+184
source_new = -2.2247e+184
source_new = -4.4560e+184
source_new = -8.9250e+184
source_new = -1.7882e+185
source_new = -3.5814e+185
source_new = -7.1762e+185
source_new = -1.4372e+186
source_new = -2.8803e+186
source_new = -5.7691e+186
source_new = -1.1555e+187
source_new = -2.3152e+187
source_new = -4.6368e+187
source_new = -9.2909e+187
source_new = -1.8607e+188
source_new = -3.7289e+188
source_new = -7.4687e+188
source_new = -1.4960e+189
source_new = -2.9973e+189
source_new = -6.0030e+189
source_new = -1.2028e+190
source_new = -2.4089e+190
source_new = -4.8274e+190
source_new = -9.6686e+190
source_new = -1.9366e+191
source_new = -3.8802e+191
source_new = -7.7715e+191
source_new = -1.5571e+192
source_new = -3.1185e+192
source_new = -6.2492e+192
source_new = -1.2516e+193
source_new = -2.5071e+193
source_new = -5.0231e+193
source_new = -1.0061e+194
source_new = -2.0158e+194
source_new = -4.0371e+194
source_new = -8.0897e+194
source_new = -1.6202e+195
source_new = -3.2474e+195
source_new = -6.5065e+195
source_new = -1.3032e+196
source_new = -2.6111e+196
source_new = -5.2293e+196
source_new = -1.0479e+197
source_new = -2.0986e+197
source_new = -4.2060e+197
source_new = -8.4246e+197
source_new = -1.6874e+198
source_new = -3.3809e+198
source_new = -6.7710e+198
source_new = -1.3567e+199
source_new = -2.7172e+199
source_new = -5.4456e+199
source_new = -1.0907e+200
source_new = -2.1847e+200
source_new = -4.3772e+200
source_new = -8.7666e+200
source_new = -1.7566e+201
source_new = -3.5180e+201
source_new = -7.0501e+201
source_new = -1.4121e+202
source_new = -2.8284e+202
source_new = -5.6669e+202
source_new = -1.1350e+203
source_new = -2.2741e+203
source_new = -4.5545e+203
source_new = -9.1270e+203
source_new = -1.8280e+204
source_new = -3.6616e+204
source_new = -7.3363e+204
source_new = -1.4693e+205
source_new = -2.9441e+205
source_new = -5.8962e+205
source_new = -1.1815e+206
source_new = -2.3664e+206
source_new = -4.7401e+206
source_new = -9.4972e+206
source_new = -1.9022e+207
source_new = -3.8112e+207
source_new = -7.6329e+207
source_new = -1.5295e+208
source_new = -3.0634e+208
source_new = -6.1400e+208
source_new = -1.2302e+209
source_new = -2.4640e+209
source_new = -4.9369e+209
source_new = -9.8873e+209
source_new = -1.9812e+210
source_new = -3.9679e+210
source_new = -7.9526e+210
source_new = -1.5934e+211
source_new = -3.1914e+211
source_new = -6.3944e+211
source_new = -1.2806e+212
source_new = -2.5661e+212
source_new = -5.1393e+212
source_new = -1.0300e+213
source_new = -2.0630e+213
source_new = -4.1321e+213
source_new = -8.2790e+213
source_new = -1.6581e+214
source_new = -3.3224e+214
source_new = -6.6539e+214
source_new = -1.3335e+215
source_new = -2.6708e+215
source_new = -5.3496e+215
source_new = -1.0718e+216
source_new = -2.1467e+216
source_new = -4.3013e+216
source_new = -8.6144e+216
source_new = -1.7263e+217
source_new = -3.4576e+217
source_new = -6.9256e+217
source_new = -1.3876e+218
source_new = -2.7791e+218
source_new = -5.5685e+218
source_new = -1.1152e+219
source_new = -2.2348e+219
source_new = -4.4760e+219
source_new = -8.9656e+219
source_new = -1.7963e+220
source_new = -3.5978e+220
source_new = -7.2087e+220
source_new = -1.4437e+221
source_new = -2.8930e+221
source_new = -5.7942e+221
source_new = -1.1614e+222
source_new = -2.3269e+222
source_new = -4.6605e+222
source_new = -9.3380e+222
source_new = -1.8702e+223
source_new = -3.7474e+223
source_new = -7.5053e+223
source_new = -1.5043e+224
source_new = -3.0139e+224
source_new = -6.0366e+224
source_new = -1.2095e+225
source_new = -2.4223e+225
source_new = -4.8538e+225
source_new = -9.7210e+225
source_new = -1.9482e+226
source_new = -3.9023e+226
source_new = -7.8160e+226
source_new = -1.5660e+227
source_new = -3.1364e+227
source_new = -6.2844e+227
source_new = -1.2586e+228
source_new = -2.5223e+228
source_new = -5.0521e+228
source_new = -1.0119e+229
source_new = -2.0275e+229
source_new = -4.0606e+229
source_new = -8.1362e+229
source_new = -1.6295e+230
source_new = -3.2655e+230
source_new = -6.5404e+230
source_new = -1.3100e+231
source_new = -2.6248e+231
source_new = -5.2569e+231
source_new = -1.0533e+232
source_new = -2.1095e+232
source_new = -4.2273e+232
source_new = -8.4668e+232
source_new = -1.6959e+233
source_new = -3.3980e+233
source_new = -6.8055e+233
source_new = -1.3636e+234
source_new = -2.7309e+234
source_new = -5.4724e+234
source_new = -1.0960e+235
source_new = -2.1954e+235
source_new = -4.3988e+235
source_new = -8.8102e+235
source_new = -1.7652e+236
source_new = -3.5353e+236
source_new = -7.0841e+236
source_new = -1.4188e+237
source_new = -2.8437e+237
source_new = -5.6976e+237
source_new = -1.1412e+238
source_new = -2.2865e+238
source_new = -4.5793e+238
source_new = -9.1758e+238
source_new = -1.8377e+239
source_new = -3.6831e+239
source_new = -7.3771e+239
source_new = -1.4776e+240
source_new = -2.9605e+240
source_new = -5.9292e+240
source_new = -1.1880e+241
source_new = -2.3794e+241
source_new = -4.7684e+241
source_new = -9.5509e+241
source_new = -1.9130e+242
source_new = -3.8329e+242
source_new = -7.6765e+242
source_new = -1.5381e+243
source_new = -3.0805e+243
source_new = -6.1734e+243
source_new = -1.2365e+244
source_new = -2.4766e+244
source_new = -4.9622e+244
source_new = -9.9383e+244
source_new = -1.9913e+245
source_new = -3.9881e+245
source_new = -7.9919e+245
source_new = -1.6007e+246
source_new = -3.2062e+246
source_new = -6.4239e+246
source_new = -1.2866e+247
source_new = -2.5779e+247
source_new = -5.1629e+247
source_new = -1.0346e+248
source_new = -2.0721e+248
source_new = -4.1505e+248
source_new = -8.3160e+248
source_new = -1.6656e+249
source_new = -3.3372e+249
source_new = -6.6836e+249
source_new = -1.3393e+250
source_new = -2.6823e+250
source_new = -5.3762e+250
source_new = -1.0772e+251
source_new = -2.1575e+251
source_new = -4.3227e+251
source_new = -8.6574e+251
source_new = -1.7348e+252
source_new = -3.4743e+252
source_new = -6.9632e+252
source_new = -1.3947e+253
source_new = -2.7935e+253
source_new = -5.5971e+253
source_new = -1.1210e+254
source_new = -2.2461e+254
source_new = -4.4985e+254
source_new = -9.0154e+254
source_new = -1.8057e+255
source_new = -3.6168e+255
source_new = -7.2466e+255
source_new = -1.4513e+256
source_new = -2.9081e+256
source_new = -5.8241e+256
source_new = -1.1672e+257
source_new = -2.3377e+257
source_new = -4.6825e+257
source_new = -9.3818e+257
source_new = -1.8790e+258
source_new = -3.7649e+258
source_new = -7.5401e+258
source_new = -1.5110e+259
source_new = -3.0264e+259
source_new = -6.0619e+259
source_new = -1.2146e+260
source_new = -2.4325e+260
source_new = -4.8740e+260
source_new = -9.7613e+260
source_new = -1.9561e+261
source_new = -3.9177e+261
source_new = -7.8474e+261
source_new = -1.5723e+262
source_new = -3.1491e+262
source_new = -6.3096e+262
source_new = -1.2637e+263
source_new = -2.5322e+263
source_new = -5.0715e+263
source_new = -1.0165e+264
source_new = -2.0366e+264
source_new = -4.0792e+264
source_new = -8.1731e+264
source_new = -1.6369e+265
source_new = -3.2800e+265
source_new = -6.5690e+265
source_new = -1.3166e+266
source_new = -2.6379e+266
source_new = -5.2835e+266
source_new = -1.0586e+267
source_new = -2.1201e+267
source_new = -4.2482e+267
source_new = -8.5082e+267
source_new = -1.7051e+268
source_new = -3.4153e+268
source_new = -6.8407e+268
source_new = -1.3706e+269
source_new = -2.7450e+269
source_new = -5.5003e+269
source_new = -1.1016e+270
source_new = -2.2076e+270
source_new = -4.4216e+270
source_new = -8.8564e+270
source_new = -1.7745e+271
source_new = -3.5539e+271
source_new = -7.1209e+271
source_new = -1.4261e+272
source_new = -2.8579e+272
source_new = -5.7241e+272
source_new = -1.1466e+273
source_new = -2.2972e+273
source_new = -4.6009e+273
source_new = -9.2187e+273
source_new = -1.8463e+274
source_new = -3.6998e+274
source_new = -7.4101e+274
source_new = -1.4843e+275
source_new = -2.9739e+275
source_new = -5.9562e+275
source_new = -1.1934e+276
source_new = -2.3901e+276
source_new = -4.7894e+276
source_new = -9.5924e+276
source_new = -1.9227e+277
source_new = -3.8522e+277
source_new = -7.7156e+277
source_new = -1.5459e+278
source_new = -3.0961e+278
source_new = -6.2039e+278
source_new = -1.2425e+279
source_new = -2.4903e+279
source_new = -4.9896e+279
source_new = -9.9937e+279
source_new = -2.0024e+280
source_new = -4.0102e+280
source_new = -8.0356e+280
source_new = -1.6093e+281
source_new = -3.2253e+281
source_new = -6.4602e+281
source_new = -1.2939e+282
source_new = -2.5926e+282
source_new = -5.1923e+282
source_new = -1.0404e+283
source_new = -2.0836e+283
source_new = -4.1758e+283
source_new = -8.3638e+283
source_new = -1.6752e+284
source_new = -3.3565e+284
source_new = -6.7223e+284
source_new = -1.3470e+285
source_new = -2.6976e+285
source_new = -5.4060e+285
source_new = -1.0828e+286
source_new = -2.1688e+286
source_new = -4.3453e+286
source_new = -8.7029e+286
source_new = -1.7438e+287
source_new = -3.4923e+287
source_new = -6.9984e+287
source_new = -1.4017e+288
source_new = -2.8076e+288
source_new = -5.6253e+288
source_new = -1.1267e+289
source_new = -2.2574e+289
source_new = -4.5211e+289
source_new = -9.0596e+289
source_new = -1.8145e+290
source_new = -3.6346e+290
source_new = -7.2822e+290
source_new = -1.4585e+291
source_new = -2.9223e+291
source_new = -5.8527e+291
source_new = -1.1728e+292
source_new = -2.3488e+292
source_new = -4.7077e+292
source_new = -9.4324e+292
source_new = -1.8892e+293
source_new = -3.7853e+293
source_new = -7.5810e+293
source_new = -1.5191e+294
source_new = -3.0423e+294
source_new = -6.0973e+294
source_new = -1.2213e+295
source_new = -2.4461e+295
source_new = -4.9011e+295
source_new = -9.8157e+295
source_new = -1.9668e+296
source_new = -3.9390e+296
source_new = -7.8941e+296
source_new = -1.5812e+297
source_new = -3.1670e+297
source_new = -6.3454e+297
source_new = -1.2708e+298
source_new = -2.5464e+298
source_new = -5.0998e+298
source_new = -1.0220e+299
source_new = -2.0470e+299
source_new = -4.1001e+299
source_new = -8.2149e+299
source_new = -1.6453e+300
source_new = -3.2966e+300
source_new = -6.6022e+300
source_new = -1.3231e+301
source_new = -2.6499e+301
source_new = -5.3078e+301
source_new = -1.0635e+302
source_new = -2.1300e+302
source_new = -4.2677e+302
source_new = -8.5471e+302
source_new = -1.7127e+303
source_new = -3.4303e+303
source_new = -6.8712e+303
source_new = -1.3767e+304
source_new = NaN
figure(1);
subplot(3,1,1)
mean(isfinite(sol.x))
ans = 1
mean(isfinite(sol.y))
ans = 1×450
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
plot(sol.x,sol.y(1,:),'color','r','Linewidth',1.2);
grid on
hold on
xlabel('\bf t'); ylabel('$$y$$','interpreter','latex','fontsize',16);
subplot(3,1,2)
plot(sol.x,sol.y(2,:),'color','r','Linewidth',1.2);
grid on
hold on
xlabel('\bf t'); ylabel('$$\dot{y}$$','interpreter','latex','fontsize',16);
subplot(3,1,3)
plot(sol.x,sol.y(3,:),'color','r','Linewidth',1.2);
grid on
hold on
xlabel('\bf t'); ylabel('$$y"$$','interpreter','latex','fontsize',16);
function dy = ode2(~,y,source)%y''+y'=1+int^1_0(y'*x)dx;y(0) = 2;y(1) = 4;
m=0.05;
dy = zeros(3,1); % создает нулевой вектор-столбец
dy(1)=y(2);
dy(2)=y(3);
dy(3)=-3/m*y(3)+1/(m.^2)*(1-2*y(2)+4.*source);
end
Torsten
2023-5-29
while error > tol%ЗАПУСТИТЕ ЦИКЛ WHILE
[T,Y] = ode45(@(t,y) ode2(t,y,source), tspan, y0);% ВЫЗЫВАЕМ СОЛВЕР BVP4C:
source_new = trapz(T,Y(:,3));
error = abs(source_new - source);
source = source_new;
end
instead of
while error > tol%ЗАПУСТИТЕ ЦИКЛ WHILE
sol = ode45(@(t,y) ode2(t,y,source), [0 1], y0);% ВЫЗЫВАЕМ СОЛВЕР BVP4C:
t = linspace(0,1,100);
source_new = trapz(t,y(3,:));
error = abs(source_new - source);
source = source_new;
end
Are you sure that "source" is really meant to be
integral_{x=0}^{x=1} y3(x) dx
and not
integral_{x=0}^{x=t} y3(x) dx
?
更多回答(1 个)
Torsten
2023-5-29
编辑:Torsten
2023-5-29
syms t y(t)
syms s real
m = 0.05;
Dy = diff(y,t);
D2y = diff(y,t,2);
D3y = diff(y,t,3);
eqn = D3y -( -3/m*D2y + 1/m^2*(1-2*Dy+4*s)) ;
sol_ode = dsolve(eqn)
sol_ode =
vars = symvar(sol_ode)
vars =
cond1 = subs(sol_ode,t,0) == 2;
cond2 = subs(diff(sol_ode,t),t,0) == 1;
cond3 = subs(diff(sol_ode,t,2),t,0) == 3;
cond4 = subs(diff(sol_ode,t),t,1) - subs(diff(sol_ode,t),t,0) == s;
sol_cond = solve([cond1,cond2,cond3,cond4])
sol_cond = struct with fields:
C1: 1663/800
C2: -(6*exp(20) + 7*exp(40))/(800*(exp(40) - 4*exp(20) + 2))
C3: (17*exp(40) + 6)/(400*(exp(40) - 4*exp(20) + 2))
s: (10*exp(40) - 23*exp(20) + 13)/(20*(exp(40) - 4*exp(20) + 2))
double(sol_cond.s)
ans = 0.5000
sol_ode = simplify(subs(sol_ode,[vars(1),vars(2),vars(3),vars(4)],[sol_cond.C1,sol_cond.C2,sol_cond.C3,sol_cond.s]))
sol_ode =
figure(1)
fplot(sol_ode,[0 1])
figure(2)
fplot(diff(sol_ode,t),[0 1])
figure(3)
fplot(diff(sol_ode,t,2),[0 1])
simplify(diff(sol_ode,t,3) -( -3/m*diff(sol_ode,t,2) + 1/m^2*(1-2*diff(sol_ode,t)+4*(subs(diff(sol_ode,t),t,1)-subs(diff(sol_ode,t),t,0)))))
ans =
0
2 个评论
Torsten
2023-5-29
A different method to solve the problem:
y0(1)=2;
y0(2)=1;
y0(3)=3;
source = 0.0;
solinit = bvpinit(linspace(0,1,100),y0,source);
sol = bvp4c(@mat4ode, @mat4bc, solinit);
sol = struct with fields:
solver: 'bvp4c'
x: [0 0.0101 0.0202 0.0303 0.0404 0.0505 0.0606 0.0707 0.0808 0.0909 0.1010 0.1111 0.1212 0.1313 0.1414 0.1515 0.1616 0.1717 0.1818 0.1919 0.2020 0.2121 0.2222 0.2323 0.2424 0.2525 … ]
y: [3×100 double]
yp: [3×100 double]
parameters: 0.5000
stats: [1×1 struct]
sol.parameters
ans = 0.5000
figure(1)
plot(sol.x,sol.y(1,:))
figure(2)
plot(sol.x,sol.y(2,:))
figure(3)
plot(sol.x,sol.y(3,:))
function dydx = mat4ode(x,y,source) % equation being solved
m = 0.05;
dydx = [y(2);y(3);-3/m*y(3)+1/(m.^2)*(1-2*y(2)+4.*source)];
end
function res = mat4bc(ya,yb,source) % boundary conditions
res = [ya(1)-2.0;ya(2)-1.0;ya(3)-3.0;yb(2)-1.0-source];
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)