Can someone help me generate numerical values ​​for this sample problem using bvp4c solver?

3 ビュー (過去 30 日間)
y'' + y = 0
Boundary conditions are y(0)=1; y(pi/2)=0.
Compute y(pi/3) and y(pi/4) using MATLAB Bvp4c solver.
Can someone help me generate numerical values for this sample problem using bvp4c solver?
I want code command to generate the values of y(pi/3) and y(pi/4).
Trial code
function sampletrial
clear all;
close all;
clc;
gva=[pi/3 pi/4];
for i=1:2
g=gva(i);
figure(1);
solinit=bvpinit(linspace(0,pi/2,50),[1 0]);
sol=bvp4c(@shootode5,@shootbc5,solinit);
eta=sol.x;
f=sol.y;
plot(eta,(f(1,:)),'--','linewidth',2);
hold on
end
function dydx=shootode5(eta,f)
dydx=[f(2)
-f(1)];
end
function res=shootbc5(fa,fb)
res=[fa(1)-1
fb(1)];
end

採用された回答

Rajeev
Rajeev 2023 年 3 月 6 日
移動済み: Image Analyst 2023 年 3 月 6 日
Can you try adding the line:
y_values(i) = interp1(sol.x, sol.y(1,:), g);
in the loop?
  1 件のコメント
VAIDEHI
VAIDEHI 2023 年 3 月 6 日
移動済み: Image Analyst 2023 年 3 月 6 日
Thank you sir.
This command worked for me. I got the values of cos(pi/3) and cos(pi/4) without putting a semicolon at the end.
y_values(i) = interp1(sol.x, sol.y(1,:), g)
Verified.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBoundary Value Problems についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by