필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How can i replace the value of A(x) in the function defined in "f1"...

조회 수: 1 (최근 30일)
Farooq Hussain
Farooq Hussain 2020년 4월 13일
마감: MATLAB Answer Bot 2021년 8월 20일
L=10;
a=0;
h=0.5;
n=20;
x=a:h:n;
%
f1=@(x,u) u * A(x);
%%% Initial Conditions %%%
u(1)=1;
for i=1:length(x)-1;
m1=h*f1(x(i), u(i));
m2=h*f1(x(i)+0.5*h, u(i)+0.5*m1);
m3=h*f1(x(i)+0.5*h, u(i)+0.5*m2);
m4=h*f1(x(i)+h, u(i)+m3);
u(i+1)=u(i)+(1/6)*(m1+2*m2+2*m3+m4);
end
plot(x,u,'k')

답변 (2개)

M
M 2020년 4월 13일
You can have a look here to know how to create if / else conditions:
Then you should not create A(x) = ... but A = ... and then access the element of A using A(i).

Ameer Hamza
Ameer Hamza 2020년 4월 13일
편집: Ameer Hamza 2020년 4월 13일
Farooq, as already explained in response to your comment here: https://www.mathworks.com/matlabcentral/answers/517280-how-can-i-plot-this-graph you can define it as an anonymous function like this
A = @(x) (0<x & x<L).*(1+0.5*(1-cos(2*pi*x/L))-1/2) + (L<x).*1;
f1=@(x,u) u * A(x);

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by