Clear Filters
Clear Filters

How do I input and solve a system of differential equations in matlab

62 views (last 30 days)
I have two differential equations that I need to solve using matlab and get plots for them. the two equations are:
m*(d^2x/dt^2) + c*(dx/dt)^2 + (K1)*x + (K2)*x +(K3)*x^3= B*l*i
and
E(t)=L*(di/dt)+R*i+B*l*(dx/dt)
m, c,K1, K2, K3,B, l, L, and R are all constants E(t)=20 + 5*sin(2t). x and i are both variables. How would I put this into matlab and solve it using ode solvers. Sorry for what is probably such a simple question, I am new to solving ode's with matlab. Thanks for your help.

Answers (2)

Sysenso Systems
Sysenso Systems on 20 Apr 2013
  4 Comments
Christopher Van Horn
Christopher Van Horn on 15 Jan 2021
@Adam Danz I totaly agree that no one has to help or do anything. The point I am trying to make is yes there are a lot of posts regarding ode's, syms, derivatives, and other advanced calculus. There are also just as many versions of Matlab. I am running my schools which is 2020a. So items like inline do not work. i do understand and I deeply apriciate your rebuttle. It is too often people get upset at others views without context or discussion. Civilization was built on discussion.
Is there any help you might be able to assist me on Q(t,h(t)) ; where h(t) is derived from dV/dt = (dh/dt / max)^0.3. and the Q(t, h(t)) is a derivative of (dh/dt)1 0 < h <= 3 and (dh/dt)2 3 < h <= 6 ?
Christopher Van Horn
Christopher Van Horn on 15 Jan 2021
lol! it seems I am looking at the problem wrong. I have been trying to differentiate normally. It seems I should have been looking at implicid differentiation. So back to my search. still any feed back would be wonderful.

Sign in to comment.


Steven Lord
Steven Lord on 15 Jan 2021
I recommend you visit the Ordinary Differential Equations category in the documentation. Several of the Topics pages listed in that category show how to start with the mathematical equations for an ODE or a system of ODEs, implement those equations in a form that the ODE solvers can accept, and call the ODE solvers to solve those ODEs.
If after reviewing those sections of the documentation you're still having difficulty with solving your specific system of ODEs please post information about the problem you're trying to solve to Answers or send it to Technical Support for assistance. Some of the information that would be useful:
  1. Show your system of ODEs (the mathematical form; the button labeled with a Sigma in the Insert section of the toolbar will let you type them in an answer or comment using LaTeX)
  2. Show how you've tried to implement them
  3. Describe the difficulty you're experiencing (Are you receiving specific errors or warnings, and if so what is the text of those messages? Does it give a different answer than you were expecting, and if so what answer were you expecting? Etc.)
If you feel a particular section of the documentation is incomplete or unclear please scroll to the bottom of the page and vote on how useful the information was. You will also be able to enter a free text explanation why you chose that rating and there you can call out the incomplete or unclear information.
  1 Comment
Christopher Van Horn
Christopher Van Horn on 15 Jan 2021
I did all of that. and more. thank you for more Ideas.
here is my attempt to speak to tech support. below this you will see my question to the community. I am still trying on my own in different forms. This is just one small item that is just beyond me, probabley because I have been at it so long.
Hello Christopher,
It was nice talking to you on phone.
For getting started with MATLAB Symbolic toolbox, I would suggest you go through the following documentation resources in the same order:
As I mentioned during the phone call, I will go ahead and close this case for now but feel free to reply if you are stuck at some point.
Sincerely,
Qasim Nazir
MathWorks Technical Support Department
--------------- Original Message ---------------
From: [christopher-vanhorn@uiowa.edu]
Sent: 1/6/2021 2:41 PM
Subject: Re: [External] Re: Assistance/Book Question [ ref:_00Di0Ha1u._5003q1N0pzs:ref ]
Sounds perfect ty
Sent from my U.S.Cellular© Smartphone
From: Qasim Nazir <support@mathworks.com>
Sent: Wednesday, January 6, 2021 2:40:48 PM
To: Van Horn, Christopher A <christopher-vanhorn@uiowa.edu>
Subject: Re: [External] Re: Assistance/Book Question [ ref:_00Di0Ha1u._5003q1N0pzs:ref ]
Hello Christopher,
Thank you for sharing your contact information and availability.
I will give you a call tomorrow (Jan 7) around 11 AM EST.
Sincerely,
Qasim Nazir
MathWorks Technical Support Department
--------------- Original Message ---------------
From: [christopher-vanhorn@uiowa.edu]
Sent: 1/6/2021 2:37 PM
Subject: Re: [External] Re: Assistance/Book Question [ ref:_00Di0Ha1u._5003q1N0pzs:ref ]
13198008602
8am to 6pm but not today have med apt
Sent from my U.S.Cellular© Smartphone
From: Qasim Nazir <support@mathworks.com>
Sent: Wednesday, January 6, 2021 1:11:05 PM
To: Van Horn, Christopher A <christopher-vanhorn@uiowa.edu>
Subject: RE: [External] Re: Assistance/Book Question [ ref:_00Di0Ha1u._5003q1N0pzs:ref ]
Hello Christopher,
Thank you for your response.
I can understand the difficulty that you face in understanding the course material and relevant code samples.
In order to further assist you, I would like to discuss the issue with you on a phone call. Please share your availability along with the phone number on which you would like to receive a call.
My availability in EST:
  • Today, Jan 6: till 5:30 PM
  • Thursday, Jan 7: 10:30 AM to 1 PM and 2 PM to 4 PM
I look forward to your reply.
Sincerely,
Qasim Nazir
MathWorks Technical Support Department
--------------- Original Message ---------------
From: [christopher-vanhorn@uiowa.edu]
Sent: 1/6/2021 10:44 AM
Subject: RE: [External] Re: Assistance/Book Question [ ref:_00Di0Ha1u._5003q1N0pzs:ref ]
I am not getting any errors. Just the wrong results. I am trying everything shown in the 4 text books and the few videos I have had
Time to watch. This is the form of problem that I have had difficulty understanding from the outset of the fall semester. I think the only reason
I passed the course is because despite my inability to code I showed exertional understanding of the underlying principles.
From: Qasim Nazir <support@mathworks.com>
Sent: Wednesday, January 6, 2021 9:45 AM
To: Van Horn, Christopher A <christopher-vanhorn@uiowa.edu>
Subject: RE: [External] Re: Assistance/Book Question [ ref:_00Di0Ha1u._5003q1N0pzs:ref ]
Hello Christopher,
Thank you for your response.
In order to assist you better please send us following information:
1) What is the current issue that you are facing with the script?
Are you getting any errors/warnings? If so, please send us the complete error message.
Are you not getting the expected results/output? If so, please share the expected output.
2) I tried executing your script. I get an error that the function "sect_area_cylinder" that is being used on line 14 of file "mycode.m" is missing. Do you get the same error?
Please provide the corresponding file for the function "sect_area_cylinder". That way I will be able to execute your script.
As I mentioned in my previous email, writing/debugging/fixing code for the customer is beyond the scope of MathWorks Technical Support. I am happy to assist you further in case of a specific question regarding a specific MATLAB function.
I hope the documentation resources that I mentioned in my previous would be helpful for your workflow. Regarding the scripts that you provided, it appears that a function named "sect_area_cylinder" is missing that results in an error. Providing the function file should resolve the issue. That's what I could figure out about your script.
I look forward to your response along with the requested information.
Sincerely,
Qasim Nazir
MathWorks Technical Support Department
--------------- Original Message ---------------
From: [christopher-vanhorn@uiowa.edu]
Sent: 1/6/2021 9:04 AM
Subject: RE: [External] Re: Assistance/Book Question [ ref:_00Di0Ha1u._5003q1N0pzs:ref ]
Thank you very much for the targeted learning materials.
Could you please fix the code that I sent to solve the problem that I also sent with the code.
This will go a long way in my learning style having a worked example and the problem that accompanied it.
It will further my understanding.
Thank you.
Christopher Van Horn
Civil Engineering | U of I College of Engineering Class of 2022
Member | UI Students for Disability Advocacy & Awareness
S. M. | American Society of Civil Engineers / UESI ID# 12182437
Disabled Veteran | Honorably Discharged United States Marine
From: Qasim Nazir <support@mathworks.com>
Sent: Wednesday, January 6, 2021 8:21 AM
To: Van Horn, Christopher A <christopher-vanhorn@uiowa.edu>
Subject: RE: [External] Re: Assistance/Book Question [ ref:_00Di0Ha1u._5003q1N0pzs:ref ]
Hello Christopher,
This is Qasim and I am writing in reference to your Technical Support case #04675755 regarding 'Assistance/Book Question'.
I understand that you want to solve a differential equation question from a textbook using MATLAB and looking for tutoring/help.
I would recommend MathWorks official documentation as it is the most updated resource, and contains several guided examples for getting started. I have listed some of the relevant documentation pages below.
The differential equations can be solved either analytically or numerically.
1) Analytical solution using Symbolic Toolbox
Please refer to the following resources for detailed documentation and guided examples.
I noticed that a piecewise function is being used in the question. You might find the following documentation page useful in this regard.
This is my community question and all my work in different formats.
Asked by Christopher Van Horn about 21 hours ago
Tags
Products

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!