WnGatRC456
WnGatRC456

Reputation: 337

Evaluate symfun at a symbolic variable instead of a number in MATLAB

I created a symbolic function in MATLAB R2021b using this script with the goal of solving an ODE.

syms phi(x) lambda L
eqn_x = diff(phi,x,2) == -lambda*phi;
dphi = diff(phi,x);
cond = [phi(0)==0, dphi(1)==0]; % this is the line where the problem starts
disp(cond)

conditions_v1

phi = dsolve(eqn_x,x,cond);

This script runs without any errors, but I want to evaluate dphi(L)==0 instead of at x=1. When I try to do this instead, I get the following error.

conditions_v2

error

Obviously, the way MATLAB is interpreting dphi(L)==0 is not correct since it is replacing the dependent parameter x with L which should be an independent parameter. Can someone recommend a fix or workaround?

I've also tried this dphi(x==L)==0 and I got the same error.

conditions_v3

Addition following kikon's comment I tried both options suggested based on the tutorial. These are the results.

  1. dphi | x = L creates a parse error in MATLAB
  2. dphi | x == L gives this result. This seems to indicate x=l OR dphi/dx which is not a condition. I'm tempted to try & in place of | to get an and, but this may not be sufficient.

conditions_v5

  1. subs(dphi, x = L) gives the same condition when I use dphi(L)==0 which is incorrect.

Upvotes: 0

Views: 84

Answers (0)

Related Questions