1

I am trying to evaluate the function in t = 1 in Matlab. How can I get an answer to the following code ?

result = dsolve('D2y-23*Dy+22*y=sin(t)','y(0)=0','Dy(0)=0');
disp(result);
disp(fnval(result, 1));

The first answer is: exp(22*t)/10185 + (23*cos(t))/970 - exp(t)/42 + (21*sin(t))/970.

But when I am trying to find the evaluation of the function in the point t =1, the progrem is throwing some exception. Maybe the 'fnval' function is not suitable for here.

1 Answer 1

3

You can use subs.

result = dsolve('D2y-23*Dy+22*y=sin(t)','y(0)=0','Dy(0)=0');
t = 1;
subs(result)

ans =   
  3.5198e+005

You could also do it using eval, which is similar to your initial approach:

eval(result)

after assigning a value to t.

You can evaluate the function for a number range, using eval together with vectorize:

t = -0.1:0.01:0.1;
plot(t,eval(vectorize(result)))

This gives:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.