Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Parametrize Odesolve and define constants by least...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-14-2017
08:16 AM

03-14-2017
08:16 AM

Parametrize Odesolve and define constants by least sqeare

Hello everyone, I am going to parametrize solving block (odesolve func) and then define corresponding coefficients by least square. But unfortunately, I meet problem after parametrization of the solve block. Could someone help me with this? Thank you in advance. You can find example of the program attached

33 REPLIES 33

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-14-2017
01:59 PM

03-14-2017
01:59 PM

Re: Parametrize Odesolve and define constants by least sqeare

Hope that the attached will help.

At the end of the attached file you also find a way to use a solve block with "minerr" to get the optimal value for a.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-15-2017
07:29 AM

03-15-2017
07:29 AM

Re: Parametrize Odesolve and define constants by least sqeare

What about this:

Viktor

Viktor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-15-2017
08:21 AM

03-15-2017
08:21 AM

Re: Parametrize Odesolve and define constants by least sqeare

Thank you very much, it works geat. The last question is about few differential equations. I need to solve a system of diff equations but fit them by the data for only one of the main variables. For example:

We have system p' (t) = a*p -B*p^2 and n' (t) = a*n; with some init cond p(0)=0 and n(0)=1; So I need fit this system by some data from p1 = [10,20,30,40] , t1= [0,1,2,3]. How it is better to do this .

Regards.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-15-2017
08:53 AM

03-15-2017
08:53 AM

Re: Parametrize Odesolve and define constants by least sqeare

Hi Viktor Korobov,

How is that to me the same program does not work?

Regards

F. M.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-15-2017
09:01 AM

03-15-2017
09:01 AM

Re: Parametrize Odesolve and define constants by least sqeare

Here is an example with a double function. There is some error when I try to use one more equation inside solve block

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-15-2017
09:12 AM

03-15-2017
09:12 AM

Re: Parametrize Odesolve and define constants by least sqeare

Ok! It was an oversight ...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-15-2017
09:22 AM

03-15-2017
09:22 AM

Re: Parametrize Odesolve and define constants by least sqeare

THis is not a point. I trying add the second equation and Mathcad then does not work. Please have a fast look on my example. It is very similar to yours.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-17-2017
05:13 AM

03-17-2017
05:13 AM

Re: Parametrize Odesolve and define constants by least sqeare

Hello everyone,

I am trying to find parameters of the set of differential equations. So, I solve st of dif equations by Odesolve (see attacehed) and then trying to minner coefficients a and Nt1 using experimental data Con and t11. The system must at least work, but I have error at Minerr step. Could someone help me with this? Thank you, very much.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-17-2017
11:26 AM

03-17-2017
11:26 AM

Re: Parametrize Odesolve and define constants by least sqeare

Obviously the guess values are at a magnitude which makes the odesolve block fail.

Changing the guess for a in the minerr block makes the block work, but the odesolveblock fails using those values:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-17-2017
12:16 PM

03-17-2017
12:16 PM

Re: Parametrize Odesolve and define constants by least sqeare

Thank you, it works now. I went further and meet the next problem.

Minerr function calculates coefficients , but they are negetive some time. How can I give additional condition where all the coefficients must be a positive value. Sorry for obstruction, it look like the last problem which I need to solve.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-17-2017
03:07 PM

03-17-2017
03:07 PM

Re: Parametrize Odesolve and define constants by least sqeare

> How can I give additional condition where all the coefficients must be a positive value.

Simply add statements like Nt1 >0 inside the solve block.

If possible Mathcad will respect it.

You may put more weight in a constraint by doing something like 10^6*Nt1 > 0.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-06-2017
09:29 AM

04-06-2017
09:29 AM

Re: Parametrize Odesolve and define constants by least sqeare

Hi everyone, I have developed a program where solve block solves a set of simple equations and then I am trying to minimize parameter value. 1) Parameter Nt is a vector. How can I use minner or least square to get such optimal vector (matrix). 2) I am going to get an optimal solution but there is 2 Input data set Con4(I4) and R(4). The solve block gives us solution let say n(I4) and p(4). I need Con4 = n(I4)+p(I4), and R4= p(I4)-n(4) to be equal. The problem is there is only 1 place for DATA in minnerr func of Mathcad.

Can someone explain how can I use a vector as variable parameter, and then implementing minner(least sqrere) for 2 data sets?

Thank you in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-06-2017
09:53 AM

04-06-2017
09:53 AM

Re: Parametrize Odesolve and define constants by least sqeare

The problem is not minerr!

The problem is that hnu is a vector and not a scalar.

Your last solve block with minerr calls the solve block function Pt (with vector hnu as argument).

Pt calls nt (with vector hnu as argument)

nt calls alph (with vector hnu as argument)

and alph tries to compare the VECTOR hnu against the SCALAR ELD[k

You cannot compare a vector with a scalar.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-06-2017
10:26 AM

04-06-2017
10:26 AM

Re: Parametrize Odesolve and define constants by least sqeare

But function Pt() works, please look on nnk=Pt() , the solution of the solve block works fine with no error.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-06-2017
10:30 AM

04-06-2017
10:30 AM

Re: Parametrize Odesolve and define constants by least sqeare

The worksheet being rather unclear and a bit of a mess to me i did not dig deep into the logic of your calculations.

I just tried to change your last solve block into a function with argument hnu which is then called vectorized, but now I got the error that Prime did not found a solution - along with the usual suggestion to change the guess values or the values of TOL and CTOL (which usually does not solve the problem).

Have you checked your solve blocks with simple sample data - do they work OK?

Its usually a good idea to make calculations, especially calcs with solve blocks work OK with scalar arguments, turn them into functions und then call those functions with vector arguments (vectorized). In your case I guess this would be quite some work as in many of your already existing functions you use variables already defined which are not arguments of the function.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-06-2017
10:50 AM

04-06-2017
10:50 AM

Re: Parametrize Odesolve and define constants by least sqeare

Sorry for a mess. The starting program was without Minerr, and worked perfectly( just solution of the equations). So as result I can define nnk=Pt(,,,Nt) as a function of Nk. But then I added a minerr block and the minerr block gives error.

It looks like I need rid of I2,hnu,LD,T, for example, redefine some new function F(I,Nt) inside minerr block. But this is the only idea.

Is it possible that miner do not understand vectors as a parametre?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-06-2017
01:12 PM

04-06-2017
01:12 PM

Re: Parametrize Odesolve and define constants by least sqeare

I already wrote above that its not Minerr, throwing the error but the function alph() (and also (alpe()) wher you compare hnu with a scalar ELD[k. As soon as hnu is not a scalar but a vector (as is the case in your sheet), the error is thrown. You can't ask if a vector is larger than 5 - you can only compare a scalar with a scalar.

Nevertheless I guess you can't fix the problem by changing alph aor alpe. You rather have to take care that hnu stays a scalar and is not a vector.

So again: Its not the vector Nt in the solve block which causes the error - its the vector hnu.

Minerr does understand vectors as argument as you can see by the following small example:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
07:41 AM

04-07-2017
07:41 AM

Re: Parametrize Odesolve and define constants by least sqeare

Hi again,

I prepared a version of the program without complicated functions inside solve block. So now the solution of the system Pt(I,Nt...alphh) is a function of the vectors. But still I have a problem with Minerr and moreover solution as a funk nnaakk=Pt(I,Nt1..) of vector do not work itself. I looked few hours on the program but I can not find something wrong.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
10:55 AM

04-07-2017
10:55 AM

Re: Parametrize Odesolve and define constants by least sqeare

The first error I encounter is this

To cope with your "error 1", instead of using

use

or

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
11:04 AM

04-07-2017
11:04 AM

Re: Parametrize Odesolve and define constants by least sqeare

Dear Werner,

I have tried this already before and this solution didnt help. See the picture or the program. Maybe someone has ideas about 2nd error?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
11:15 AM

04-07-2017
11:15 AM

Re: Parametrize Odesolve and define constants by least sqeare

Additionally there was again a problem with Primes automatic labeling.

Two of the "j" are labeled differently - either label both "automatic" or both "variable"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
11:25 AM

04-07-2017
11:25 AM

Re: Parametrize Odesolve and define constants by least sqeare

Yes I have done this to transfer "j" parameter to the func nt(I,n,p,j..). This mean that I calculate summarise action for j=0, j= 1, transfer this values in funk nt(t), and then calculate nt() with parameter "j". I had complicated program before where this principle worked. But after simplifying everyshing, i encountered this problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
12:07 PM

04-07-2017
12:07 PM

Re: Parametrize Odesolve and define constants by least sqeare

???

have you changed as explained above the labels of the two highlighted "j"'s to be the same?

Click on any of them, chose "Labels" on the "Math" ribbon and then set it to same as the other.

Then Pt should evaluate without errors.

The call of nt moans about an incorrect number of arguments then.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
01:03 PM

04-07-2017
01:03 PM

Re: Parametrize Odesolve and define constants by least sqeare

Thank you!!!! Now I see. How U have found this, it is impossible. You are awesome. IT works now, nut I still have a problem with error 2.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
01:49 PM

04-07-2017
01:49 PM

Re: Parametrize Odesolve and define constants by least sqeare

artem musiienko wrote:

Thank you!!!! Now I see. How U have found this, it is impossible

Nearly

Experience helped. As the expression was correct and had to work but didn't I remembered that Prime very often fails when trying to autodetect the correct label for a name. This is very nasty as those errors are really hard to spot unless you know what you should be looking for.

IT works now, nut I still have a problem with error 2.

Prime is right with its error message. I is not defined, so which value would you like I to be?

I replaced I by 10^14.

Next error: You used T1 as a scalar for a result of function Pt and in the next line as a function with argument I1. -> T1(I1) ???

Guessed it was a typo and you meant T1*I1. But Prime seems not to be able to come even close to fulfill the desired equation. Not sure, why. Maybe because your values are around the precision limit of mathcads numerics which is around 15-16 decimals.

BTW. you could also use

in your solve block.

Here's what i got:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
02:05 PM

04-07-2017
02:05 PM

Re: Parametrize Odesolve and define constants by least sqeare

Dear Werner , I will explain you what I need. I have data set Con1(I1), where Con1 is conductivity as a function of Intensity I1. So I have solved equations in 1st solve block and get p(I) or Pt(I..). So now I need compare Pt(I1) with Con(I1) by Minner in the points I1. See the last picture in the Mathcad file to see dada.

So I defined T1 as Pt(I,..) and then defined the T1(I1) in points I1 and now trying compare with Con1. SO T1*I1 is wrong it must be T1(I1) and T1 must be a function of "I"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
02:27 PM

04-07-2017
02:27 PM

Re: Parametrize Odesolve and define constants by least sqeare

Here is example with some solution an experimental data, see the last picture.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
03:10 PM

04-07-2017
03:10 PM

Re: Parametrize Odesolve and define constants by least sqeare

For the next few days or week I will be unable to open Prime files from versions higher than 3.0. Maybe someone else can continue to help you out.

After all "I" was not defined but used in your previous sheet and "T1" was a scalar.

If you want to use a function "T1" (better give it a different name) you would first have to define that function before you can use it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-07-2017
03:30 PM

04-07-2017
03:30 PM

Re: Parametrize Odesolve and define constants by least sqeare

A last idea - may this works for you (can't check)