how to view struct with fields?

syms x(t) y(t) v(t) m c g s=symengine disp ('1)------------------------------------------') cond1=x(0)==0; cond2=diff(x,t)==0; conds=[cond1 cond2] dx=diff(x,t); dx2=diff(x,t,2); dv=diff(v,t); dx2=diff(x,t,2); ode=m*diff(v,t)+c*v==m*g
Sol=solve(ode,conds,dx,x)

 Accepted Answer

You can access the fields of a struct using dot notation. For example
Sol.c
Sol.g
Also, since you are trying to solve a differential equation, use dsolve(),
Sol=dsolve(ode,conds)

8 Comments

but still I cannot find the result I wanted :/
It is not clear which differential equation you are trying to solve. Can you clearly specify the required equations.
madhan ravi
madhan ravi on 2 Jun 2018
Edited: madhan ravi on 2 Jun 2018
I want to solve m(dx.^2/dt.^2)+c(dx/dt)=m*g; where m = mass, c=air resistance , g=acceleration due to gravity , x=distance travelled , x(0)=0, dx/dt(0)=0.
You can solve this equation as follow
syms x(t) m c g
disp ('1)------------------------------------------')
dx = diff(x);
cond1=x(0)==0;
cond2=dx(0)==0;
conds=[cond1 cond2];
ode = m*diff(x,2) + c*diff(x) == m*g;
Sol=dsolve(ode,conds)
Sol =
(g*m*t)/c - (g*m^2)/c^2 + (g*m^2*exp(-(c*t)/m))/c^2
Thank you so much you are great
You are welcome.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!