matlab - fsolve error when solving a quadratic function -


so im trying use fsolve in code below, keep on getting error , have no clue on how fix it, appreciated. reference use (1/2,1,1,1/2,0) input arguments.

function [ b_a , a_b ] = secondordersimulation(delta,c1,c2,s0,m2a_current) m1a_current = (-delta -c2*m2a_current)/c1; m1b_current = 0; m2b_current = 0; syms t positive; b_a = []; a_b = [];     k = 0:5       if mod(k,2)==0 || k==0 %if k / interval a_n b_n             f = c1*(m1a_current + (1+s0)*t) +c2*(m2a_current + m1a_current*t  + ((1+s0)*(t)^2)/2) - delta;         solve_even = fsolve(f,1);         b_a = [b_a solve_even];         m1b_next = m1a_current + (1+s0)*solve_even;         m2b_next = (delta - c1*m1b_next)/c2;         m1b_current = m1b_next;         m2b_current = m2b_next;       else %if k odd / interval b_n a_n+1         g = c1*(m1b_current - (1-s0)*t) +c2(m2b_current + m1b_current*t - ((1-s0)*(t)^2)/2) + delta;         solve_odd = fsolve(g,1);         a_b = [a_b solve_odd]         m1a_next = m1b_current  - (1-s0)*solve_odd;         m2a_next = -(delta +c1*m1a_next)/c2;         m1a_current = m1a_next;         m2a_current = m2a_next;       end      end end 

also, sorry in advance terrible variable labelling.

>> secondordersimulation(1/2,1,1,1/2,0) error using lsqfcnchk (line 108) if fun matlab object, must have feval method.  error in fsolve (line 210) funfcn = lsqfcnchk(fun,'fsolve',length(varargin),funvalcheck,gradflag);  error in secondordersimulation (line 11)         solve_even = fsolve(f,1); 

the first argument fsolve has function handle, should write f , g anonymous functions:

f = @(t) c1*(m1a_current + (1+s0)*t) +c2*(m2a_current + m1a_current*t ...          + ((1+s0)*(t)^2)/2) - delta;  g = @(t) c1*(m1b_current - (1-s0)*t) +c2(m2b_current + m1b_current*t ...          - ((1-s0)*(t)^2)/2) + delta; 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -