# How to employ frequency-depend parameter in Xcos diagram?

**URL:** <https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554>\
**Category:** Xcos\
**Created:** [June 14, 2024, 7:23am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554 "2024-06-14T07:23:45Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alex](https://scilab.discourse.group/u/Alex)\
**Post date:** [June 14, 2024, 7:23am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/1 "2024-06-14T07:23:45Z")

</div>

I am making a mechanical simulation of spring damper system in Xcos.  
And I want to employ frequency-depend damping coefficient parameter in it.  
Please teach me how to employ such a block.  
i.e. Which block to use, and how to set it.  
Or such a simulation is unable?

Best regards.

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 14, 2024, 11:19am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/2 "2024-06-14T11:19:54Z")

</div>

Hello, and welcome to Scilab’s discourse !

You won’t find such a block in Xcos, but in order to build the simulation of such a system, you should first write the differential equation that governs such a system. What is your model of frequency-depend damping ?

S.

---

<div class="post-metadata">

**Author:** ![Alex](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alex](https://scilab.discourse.group/u/Alex)\
**Post date:** [June 16, 2024, 11:54pm UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/3 "2024-06-16T23:54:38Z")

</div>

Dear mottelet,

Thank you very much for your reply.  
I understood there is no such a block in Xcos.  
My model is spring-damper mechanical model.  
It’s differential equation is:  
mx" + c(f)x’ + kx = 0 (1)  
I already solved above equation for fixed “c” by Xcos.  
This time the damping coefficient “c” has some frequecy dependence.  
I already have the frequency curve and its equation of “c”.  
So I want to solve above equation (1).  
Please advice the method.

Best regards.

Alex

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 17, 2024, 6:15am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/4 "2024-06-17T06:15:58Z")

</div>

How do you define the instantaneous frequency f with respect to y ?

S.

---

<div class="post-metadata">

**Author:** ![Alex](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alex](https://scilab.discourse.group/u/Alex)\
**Post date:** [June 17, 2024, 7:27am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/5 "2024-06-17T07:27:46Z")

</div>

Do you mean instantaneous frequency f with respect to time?

Alex.

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 17, 2024, 8:21am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/6 "2024-06-17T08:21:32Z")

</div>

> [@Alex](#):
>
> mx" + c(f)x’ + kx = 0

I was just asking how you define f in the above equation. Since x is a function of time, I was supposing that f also does. That’s why I was asking how you define f… The concept of frequency depending damping is easy to define for individual eigenmodes e.g. of the 1D wave equation. In that case each mode n is a scalar oscillator like yours with a given eigenfrequency f\_k=\frac{1}{2\pi}\sqrt{k\_n/m\_n} in that case it is straightforward to define the damping coefficient as a function of f\_k.

But in your case (a single oscilator), when c(f)=0 the solution of the ode has the general form

x(t)=a\cos(\omega t)+b\sin(\omega t),

where \omega=\sqrt{k/m} hence you necessarily have f=\frac{\omega}{2\pi}. That’s why I ask you what is your definition of f in the general case.

S.

---

<div class="post-metadata">

**Author:** ![Alex](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alex](https://scilab.discourse.group/u/Alex)\
**Post date:** [June 18, 2024, 12:05am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/7 "2024-06-18T00:05:58Z")

</div>

Dear mottelet,

I am sorry for the differential equation format.  
My target differential equation is:  
mx" + cx’ + kx = 0 (1)  
I measured the “c”(tanδ) of the damper by viscoelasticity measuring equipment such as:  
[http://www.ubm-rheology.co.jp/product/seihin/rheogel-e.shtml](http://www.ubm-rheology.co.jp/product/seihin/rheogel-e.shtml)  
then I got tanδ of the damper and it has some frequency dependence.  
Now I want to solve the differential equation (1) considering the “c” (or tanδ).  
Could you understand my needs?  
Or if there is mistake in my thinking please correct.

Best regards,

Alex

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 18, 2024, 6:29am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/8 "2024-06-18T06:29:42Z")

</div>

This type of dynamic mechanical analyzer work by applying an oscillating force to a material. In my humble opinion, your equation should have a right hand side (instead of 0), like this:

mx" + c(f)x’ + kx = F\sin(2\pi f t).

S.

---

<div class="post-metadata">

**Author:** ![Alex](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alex](https://scilab.discourse.group/u/Alex)\
**Post date:** [June 18, 2024, 7:18am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/9 "2024-06-18T07:18:15Z")

</div>

Dear mottelet

As you told, my model is  
mx" + c(f)x’ + kx = Po sinωt  
I am sorry for confusing you.  
Now can you give me answer to my question?

Alex

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 18, 2024, 11:23am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/10 "2024-06-18T11:23:35Z")

</div>

Do you have an example of c(f) formula ?

S.

---

<div class="post-metadata">

**Author:** ![Alex](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alex](https://scilab.discourse.group/u/Alex)\
**Post date:** [June 19, 2024, 2:18am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/11 "2024-06-19T02:18:21Z")

</div>

Dear mottlelet.

Actually I have tanδ formula. It is:  
tanδ = 0.23ln(f) for f = 10 to 1[kHz]

Best regards,

Alex

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 19, 2024, 8:28am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/13 "2024-06-19T08:28:35Z")

</div>

OK. Here is a simple Xcos diagram:

[osc.zcos](https://scilab.discourse.group/uploads/short-url/6QiOsDSKTL1rZBJf0IXKELg2MIC.zcos) (3.0 KB)

 ![Screenshot 2024-06-19 at 10.21.59](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/812d43d1c76b1608670a8350ea1b1395a6e45f73.png)  
 ![Screenshot 2024-06-19 at 10.22.29](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/6ffd26600c2bd838b4f6d63dbfa4b263bd17ad07.jpeg)  
and the simulation context (where you can change f and other parameters):  
 ![Screenshot 2024-06-19 at 10.24.16](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/c3c975cf41eb28672dbe7b904b44573af401bdfc.jpeg)

---

<div class="post-metadata">

**Author:** ![Alex](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alex](https://scilab.discourse.group/u/Alex)\
**Post date:** [June 20, 2024, 6:36am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/14 "2024-06-20T06:36:52Z")

</div>

Dear mottelet.

Thank you so much for your answer.  
Now I can do the same calculation as you.  
But my goal is to know the frequency charastaristic of the system.  
So I want to give charp waveform viberataion to the sysmtem as:  
x = sin(2π・t^3), f = t^3/(2π)  
In this case how can I do the simulation?  
Maybe I should use the script of Scilab but I do not know well.  
Please teach me.

Best regards,

Alex

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 20, 2024, 8:15am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/15 "2024-06-20T08:15:31Z")

</div>

> [@Alex](#):
>
> x = sin(2π・t^3), f = t^3/(2π)

If you take \sin(2\pi t^3)=\sin(2\pi f t) as right hand side, then f=t^2, right ? In any case, this yields an ill-posed system at t=0 since your damping is proportional to \log(f)=\log(t^2). However, it should be OK by starting with a strictly positive initial time. I think it will be easier for you to play with this small script (compared to a Xcos diagram):

```auto
function dXdt=rhs(t,X)
    x = X(1);
    v = X(2);
    m = 1;
    k = 10;
    P0 = 1;
    f = t^2;
    c = 0.23*log(f);
    dXdt = [v; (P0*sin(2*%pi*f*t)-c*v-k*x)/m]
endfunction

tspan = [%eps 5];
X0 = [0;0];
[t,X] = cvode(rhs,tspan,X0);
x = X(1,:);
v = X(2,:);
clf
plot(t,x,t,v)

```

![inter](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/067cead54c3ca7a4a4417462643fc7f3b426258b.svg)

---

<div class="post-metadata">

**Author:** ![Alex](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alex](https://scilab.discourse.group/u/Alex)\
**Post date:** [June 21, 2024, 6:18am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/16 "2024-06-21T06:18:36Z")

</div>

Dear mottelet san,

Thank you very much for your answer.  
I almost understood.  
But I am not good at Scilab script very well. So I should study.

Alex

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 21, 2024, 9:03am UTC](https://scilab.discourse.group/t/how-to-employ-frequency-depend-parameter-in-xcos-diagram/554/17 "2024-06-21T09:03:17Z")

</div>

The key point is to reformulate the original second order in time ode into a system of two first order odes (most ode solvers deal only with first order systems of odes). Here we state that X\_1=x and X\_2=x', so that

X\_1'=x'=X\_2,

and

X\_2'=x''=\frac{1}{m}\left( P\_0\sin(2\pi f t)-cX\_2-kX\_1)\right),

from the ode solver point of view, the function rhs(t,X) yields the vector

X'=\left(\begin{array}{c} X\_2\\ \frac{1}{m}\left( P\_0\sin(2\pi f t)-cX\_2-kX\_1\right) \end{array} \right)

but, by starting with

```auto
x = X(1);
v = X(2);

```

we recall the convention that has been used (first component of X is the position x, second is its derivative v=x'), and the rest of the code is more readable as we use `x` and `v` instead of `X(1)` and `X(2)`.

S.
